![](/img/trans.png)
[英]PHP Content-Disposition header: Specialcharacters in the filename
[英]Firefox downloads retrieve.php instead of filename given per Content-Disposition header
我有一个名为retrieve.php的PHP脚本,该脚本将目录中的已上传文件压缩为.zip文件,然后将它们输出到流中,因此可以下载所述文件。
该脚本可在除Firefox之外的所有浏览器中使用。 在网上搜索了一段时间之后,遇到了这个问题: PHP下载脚本返回的是download-file.php而不是filename,并且仍然存在相同的问题,我很困惑,不知道出了什么问题。
这是用于下载文件的代码:
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;
我尝试将标头设置为不同的值,例如content-type:application / force-download,在文件名后添加星号(*),等等,但都无济于事。
Firefox中的结果如下所示:
对此事的任何帮助将不胜感激。
变量名$ 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.