[英]PHP force header download not working on zip files
我有一个文档下载站点,可在其中跟踪下载的文件。
我的问题是要通过正在使用的脚本下载zip文件。 除zip文件外,其他所有文件都必须下载。 当一个zip文件被推送时,它会直接进入该脚本所在的download.php页面,而没有文件被推出。
ob_start();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($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;
这是一个对我有用的代码片段:
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
header('Content-Type: "application/octet-stream"');
header('Content-Disposition: attachment; filename="'.basename($file_url).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: ".filesize($file_url));
} else {
header('Content-Type: "application/octet-stream"');
header('Content-Disposition: attachment; filename="'.basename($file_url).'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".filesize($file_url));
}
readfile($file_url);
遇到类似的问题,这段时间对当时的情况有所帮助:
header('Content-Disposition: attachment; filename="'.basename($file).'"');
我没有使用base_name
作为内容的配置和长度,而是使用了完整路径。 使用base_name
对我base_name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.