PHP 下載 求指點
$file="Koala.jpg";
if(file_exists($file)){
header('Content-Description: File Transfer');//應該是內容簡介 對應的是什麼不太清楚
header('Content-Type: application/octet-stream'); //檔案類型,以八位位元組流
header('Content-Disposition: attachment; filename='.basename($file)); //下載一個目前的目錄下的檔案名稱為$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();
}
?>
這是我在網上蕩的一個 成功的下載代碼 我已經測試過了。
但是由於手冊上面提供的void header ( string string [, bool replace [, int http_response_code]] )
並沒有太過於詳細的介紹 所以我猜測了一下代碼的大體意思
上面的那段header 是否是彈出 下載提示框的 資訊? 希望有高手能給點詳細的
------解決方案--------------------
下載只要有主要幾項就可以:
PHP code
$file = 'ASDFGgg.pdf';_Download("files_dir/".$file, $file);function _Download($f_location,$f_name){ header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($f_location)); header('Content-Disposition: attachment; filename=' . basename($f_name)); readfile($f_location); }