0
我寫了這個功能,一切正常,直到我試圖打開下載的副本,它顯示該文件無效。這裏是我的功能強制下載工作,但試圖在本地打開時顯示無效
function download_file() {
//Check for download request:
if(isset($_GET['file'])) {
//Make sure there is a file before doing anything
if(is_file($this->path . basename($_GET['file']))) {
//Below required for IE:
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
//Set Headers:
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->path . basename($_GET['file'])) . ' GMT');
header('Content-Type: application/force-download');
header('Content-Disposition: inline; filename="' . basename($_GET['file']) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($this->path . basename($_GET['file'])));
header('Connection: close');
readfile($this->path . basename($_GET['file']));
exit();
}
}
}
編輯:通過無效比如我下載的圖片,並嘗試在iPhotos或Windows圖片查看器來查看它,它說,文件格式不支持。當我在服務器上查看它時,它看起來很好,但下載後它已損壞。
在一個不相關的注意:該功能基本名()提供對LFI攻擊的保護? – 2010-05-16 17:15:21
你需要更具體。它是如何「無效」?它的內容是什麼? – Artefacto 2010-05-16 17:27:05
用簡單的文本文件嘗試一下,並用十六進制查看器查看下載的數據。 – Gumbo 2010-05-16 18:12:28