如何启动/强制下载外部以PHP或其他语言存在的文件? [英] How do you initiate/force a download for files that reside externally in PHP or other language?
本文介绍了如何启动/强制下载外部以PHP或其他语言存在的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果你有外部的图像或其他文件,当用户点击它时,如何强制浏览器下载链接?
If you have images or other files that reside externally, how do force the browser to download the link when a user click on it?
使用Content-disposition:attachment; header会这样做,但它不适用于外部驻留的文件而不在本地读取和导入文件。
The use of "Content-disposition: attachment;" header would do that, but it is not working for files that resides externally without reading and importing the file locally.
推荐答案
你将必须先在服务器上加载资源。你可能也想做一些缓存:
You will have to load the resource on the server first. You might want to do some caching also:
<?php
header("Content-disposition: attachment; filename=myfile.jpg");
echo file_get_contents("http://host.tld/path/to/myfile.jpg");
?>
这篇关于如何启动/强制下载外部以PHP或其他语言存在的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文