Cor*_*ory 1 html php java http-headers
如果你有外部的图像或其他文件,当用户点击它时,如何强制浏览器下载链接?
使用"内容 - 处置:附件;" header会这样做,但是对于没有在本地读取和导入文件而驻留在外部的文件它不起作用.
您必须首先在服务器上加载资源.您可能还想要进行一些缓存:
<?php
header("Content-disposition: attachment; filename=myfile.jpg");
echo file_get_contents("http://host.tld/path/to/myfile.jpg");
?>
Run Code Online (Sandbox Code Playgroud)