php:强制下载到高清?

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Cache-Control: private",false);
header("Content-type: application/force-download");
header("Content-disposition: attachment; filename=\"". $file ."\";");
header("Content-transfer-encoding: binary");
header("Content-Length: ".filesize($file));
file_get_contents($file);
readfile($file);
exit();

知道我做错了什么吗?这不应该从我的服务器下载任何文件用户的硬盘吗?不知何故,每个文件都被损坏!此外,我想知道如何更改下载文件文件名?

$file始终包含我的文件的完整路径.
如果我尝试标题(‘Location:’.$file);浏览器成功打开我的文件.但是如果文件是.jpg,则浏览器不会提示下载窗口.相反,它只是在浏览器窗口中打开文件.我希望每个文件都下载到高清.

请帮帮我们.我现在已经这么一个星期了,我找不到解决方案了吗?

为什么不用

header(“Content-type:application / octet-stream”);

而不是“强制下载”

另外你为什么要做file_get_contents和readfile?只需要一个 – 你基本上包括两次文件,这就是它被破坏的原因.以下是我将如何执行上面的代码

header("Cache-Control: no-cache");
header("Expires: -1");
header("Content-Type: application/octet-stream;");
header("Content-disposition: attachment; filename=\"" . basename($file) . "\";");
header("Content-transfer-encoding: binary");
header("Content-Length: " . filesize($file));
echo file_get_contents($file);

这应该足够了 – 只要文件确实存在

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...