强制从外部服务器下载并重命名 [英] Force download from external server and rename
问题描述
我需要下载一个外部文件并重命名,但不使用readfile(),file_get_contents ()或fread()(文件太大,无法在服务器上读取它们,并在访问者PC上再次下载)。
我已尝试过:
代码:
header(Location:http://www.example.com/example_download.zip);
它适用于下载,但不适用于example_download.zip重命名。
所以我试过readfile():
代码:
header(Content-Disposition:attachment; filename =example_download_2.zip\\\
\\\
);
header(Content-Type:application / force-download);
readfile(http://www.example.com/example_download.zip);
退出;
使用上述代码,它可以正常工作,首先在服务器上下载远程文件,将其重命名以新名称发送给访问者,但是这个过程的资源使用率非常高,并且还有带宽使用率。
所以我在寻找一种方式生成外部文件的强制下载,重新命名它,并以新名称生成下载,但直接从源文件下载。我可以吗?
提前感谢
感谢
HTML5现在允许您通过下载
属性来执行所需的任务:
< a href =http://www.example.com/example_download.zipdownload =custom_filename.zip>
链接
< / a>
更多信息:
http://developers.whatwg.org/links.html#attr-hyperlink-download
http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download
I need help with a problem in a tool that Im developing.
I need to download an external file and rename it, but without using readfile(), file_get_contents() or fread() (the files are too big to read them on the server and download it again at visitor PC).
I have tried first with:
Code:
header("Location: http://www.example.com/example_download.zip");
It works for the download, but no for the example_download.zip rename.
So I have tried with readfile():
Code:
header("Content-Disposition: attachment; filename="example_download_2.zip"\n\n");
header("Content-Type: application/force-download");
readfile("http://www.example.com/example_download.zip");
exit;
With the above code it works well, downloading the remote file first on the server, renaming it and after sending it to the visitor with the new name, but the resources usage of this process is very high, and also the bandwidth usage.
So I'm looking for a way to generate a force-download of an external file, renaming it on the fly and generating a download with the new name but downloading directly from the source. I'ts possible?
Thanks in advance Regards
HTML5 now allows you to do what you want through the download
attribute:
<a href="http://www.example.com/example_download.zip" download="custom_filename.zip">
Link
</a>
More Info:
http://developers.whatwg.org/links.html#attr-hyperlink-download http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download
这篇关于强制从外部服务器下载并重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!