加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php:强制下载到高清?

发布时间:2020-12-13 13:44:50 所属栏目: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: attachme
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);

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读