Php代碼
$file = get_file_address();// 檔案的真真實位址(支援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(); //重要的就是這個函數的調用, 清空但不關閉輸出緩衝, 否則下載的檔案頭兩個字元會是0a
flush();
readfile($file); // 輸出檔案內容
}
?>
-----------------------EOF------------------------
本文出自“pswzyu的技術部落格”
http://www.bkjia.com/PHPjc/478673.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478673.htmlTechArticlePhp代碼 ?php $file = get_file_address();// 檔案的真真實位址(支援url,不過不建議用url) if (file_exists($file)) { header(Content-Description: File Transfer); header...