微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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);

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

原文地址:https://www.jb51.cc/php/138539.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐