通过 php header 隐藏下载地址
我有另一个域的链接(例如: http://domain2.com/file.zip )。请问如何隐藏此链接并强制下载。我尝试但无法隐藏此文件网址;
header('Content-Description: File Transfer');
header("Location: $datas", true, 303);
I have a link of another domain (ex : http://domain2.com/file.zip ). Can i ask how to hide this link and force download. I try but can't hide this file url;
header('Content-Description: File Transfer');
header("Location: $datas", true, 303);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要查看类似
readfile
的内容。请参阅示例一了解设置它的代码。您可能需要将内容类型标头更改为:header('Content-Type: application/octet-stream');
仅供参考。编辑
此外,由于这将从您的其他域读取,因此它将下载到您的服务器到用户的计算机,因此可以说它会“重复”带宽。如果您有权访问其他域/它位于同一服务器上,则最好在本地读取该文件,或者在域 2 上设置类似的下载脚本,因此您只需将它们重定向到域 2 的下载脚本,而不是文件。
You will need to look into something like
readfile
. See example one for the code to set it up with. You will probably need to change the content-type header to be:header('Content-Type: application/octet-stream');
as an fyi.EDIT
Also, since that will be reading from your other domain, it will download to your server to the user's computer, so it will be "dupping" bandwidth so to speak. If you have access to the other domain / it is on the same server, it would probably be better to read that file locally, or setup a similar download script at domain2, so you just redirect them to that download script for domain2 instead of the file.