我写了这个函数,一切正常,直到我尝试打开下载的副本,它显示该文件无效。这是我的功能
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图片查看器中查看它,它说,文件格式不支持。当我在服务器上查看它看起来很好但下载后它已损坏。
答案 0 :(得分:1)
感谢Gumbo,尝试过并输出:
警告:gmdate()期望 参数2为long,给出字符串 在 C:\ Program Files \ Wamp中 服务器\ WWW \ TutToasterUpload \ PHPClass.php 在线 83 左看看是什么 发生
修正了这一行:
//Added filemtime();
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($this->path . basename($_GET['file']))) . ' GMT');