Php代碼
<?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的技術博客”