Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP强制下载不起作用_Php_Header_Download_Content Type_Content Disposition - Fatal编程技术网

PHP强制下载不起作用

PHP强制下载不起作用,php,header,download,content-type,content-disposition,Php,Header,Download,Content Type,Content Disposition,这是我的问题。我正在尝试使用头文件下载文件。这是我的密码: $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-Desc

这是我的问题。我正在尝试使用头文件下载文件。这是我的密码:

$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');
但是,这样做的唯一结果是页面显示文件的内容(它是一个文本文件),或者如果文件是image/zip/exe等,则显示一系列奇怪的符号


如何解决此问题?

首先,不推荐使用
mime\u content\u type()

我已经检查了你的代码,它在我的服务器上运行良好,对我来说也运行良好。您应该检查可能阻止下载的INI指令。尝试重新安装服务器


此外,在您输入问题的代码片段之前,脚本不应生成任何输出。

删除内容长度标题,然后再试一次。.这对我有用吗?哪个浏览器?首先,删除所有不需要或未定义的响应头字段(内容描述、内容传输编码、缓存控制:公共…)