0
这是我的问题。我正在尝试使用标题下载文件。这里是我的代码:PHP强制下载不起作用
$content_type = mime_content_type('uploads/MyBBIntegrator_v1.3.1.zip');
$file = 'uploads/MyBBIntegrator_v1.3.1.zip';
header("Cache-Control: public");
header('Content-type: application/octet-stream');
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="MyBBIntegrator_v1.3.1.zip');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile('uploads/MyBBIntegrator_v1.3.1.zip');
然而,这样做的唯一结果是,页面显示该文件的内容(这是一个文本文件)或奇怪符号的字符串,如果该文件是图像/ ZIP/exe等
我该怎么做才能解决这个问题?
删除内容长度标题并尝试.. – 2012-08-07 11:29:59
它为我工作?哪个浏览器? – 2012-08-07 13:10:34
作为开始,删除所有不需要或未定义的响应头字段(Content-Description,Content-Transfer-Encoding,Cache-Control:public ...) – 2012-08-13 08:17:36