[英]Firefox downloads retrieve.php instead of filename given per Content-Disposition header
I have a PHP script called retrieve.php that compresses uploaded files from a directory in to a .zip file and then outputs them to the stream, so said file can be downloaded. 我有一个名为retrieve.php的PHP脚本,该脚本将目录中的已上传文件压缩为.zip文件,然后将它们输出到流中,因此可以下载所述文件。
The script works in all browsers except Firefox. 该脚本可在除Firefox之外的所有浏览器中使用。 After searching online for quite a while now and coming across this question: PHP download script returns download-file.php instead of filename and still having the same issue, I'm stumped and have no clue what's going wrong. 在网上搜索了一段时间之后,遇到了这个问题: PHP下载脚本返回的是download-file.php而不是filename,并且仍然存在相同的问题,我很困惑,不知道出了什么问题。
This is the code being used to download the file: 这是用于下载文件的代码:
if ($zippedElements >= 1) {
// die($zipFilename);
$zipFilename = "download-".time().".zip";
// Send zip to recipient
header("Content-Dispositon: attachment; filename=\"$zipFilename\"");
header("Content-Length: ".filesize($zipFileName));
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Connection: Keep-Alive");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Accept-Ranges: bytes");
readfile($zipFileName);
} else return;
I've tried setting the header to different values, such as content-type: application/force-download, adding the asterisk (*) after filename, etc., but all to no avail. 我尝试将标头设置为不同的值,例如content-type:application / force-download,在文件名后添加星号(*),等等,但都无济于事。
The result in Firefox looks as follows: Firefox中的结果如下所示:
Any help with the matter would be much appreciated. 对此事的任何帮助将不胜感激。
You have inconsistencies in the variable name $zipFilename - the N is uppercased sometimes. 变量名$ zipFilename中存在不一致的地方-N有时是大写的。
$zipFilename = __FILE__;
// Send zip to recipient
header("Content-Dispositon: attachment; filename=\"$zipFilename\"");
header("Content-Length: ".filesize($zipFilename));
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Connection: Keep-Alive");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Accept-Ranges: bytes");
readfile($zipFilename);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.