欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php隱藏實(shí)際地址的文件下載方法

 更新時間:2015年04月18日 15:45:46   作者:不吃皮蛋  
這篇文章主要介紹了php隱藏實(shí)際地址的文件下載方法,涉及php中header與file_get_contents方法的相關(guān)使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php隱藏實(shí)際地址的文件下載方法。分享給大家供大家參考。具體如下:

下面這段php代碼可不透露實(shí)際的文件下載地址。

function download_document($filename,$path="",$mimetype="application/octet-stream")
{
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Disposition: attachment; filename = $filename");
 header("Content-Length: " . filesize($pathto . $filename));
 header("Content-Type: $mimetype");
 echo file_get_contents($pathto . $filename);
}

實(shí)現(xiàn)方法二:

<?php
$file = "1.txt";// 文件的真實(shí)地址(支持url,不過不建議用url)
if (file_exists($file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($file));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit;
}
?>

希望本文所述對大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論