<?
$file = $_GET["file"];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".basename($file));
header("Content-Transfer-Encoding: binary");
$fd = fopen($file, "rb"); //大檔案下載的解決方法~readfile($file)會出問題~
if($fd)
{
ob_end_clean();
fpassthru($fd);
}
fclose($fd);
?>
將以上程式儲存成download.php
然後要下載的聯結就以如下方式呼叫:
download.php?file=XXXX
XXXX必須為檔案的完整徑名~~