我试图强制用户下载文件.为此我的脚本是:
$file = "file\this.zip";
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip"); //This is what I need
header("Content-Transfer-Encoding: binary");
readfile($file);
Run Code Online (Sandbox Code Playgroud)
我要上传的文件不是.zip,所以我想知道我要在$ file中收到的图像的内容类型.如何做到这一点
我总是把application/octet-stream
(或像这样的somwething)因为浏览器不能尝试以任何方式显示它,它总是强制用户保存/运行,然后文件类型通常由扩展名推断.