本文介绍了PHP:通过其url下载图片并提示用户保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是最好的使用户点击下载按钮,然后自动获取图像文件,然后将其下载到他们的通用下载文件夹或提示他们保存?
Whats the best what to enable a user to click a download button that then automatically gets a image file and then downloads it to their generic downloads folder or prompts them to save it?
我尝试了以下但没有成功:
i have tried the following but with no success:
$file = $art[0]['location']; // this is the full url to image http://....image.jpg
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file_content = curl_exec($ch);
curl_close($ch);
ect或我正在这一切都错了(可能)
ect or am i going about this all wrong (probably)
谢谢
推荐答案
在回覆数据之前:
header('Content-Disposition: attachment; filename=save_as_name.jpg');
然后
echo file_get_contents("http://...");
这篇关于PHP:通过其url下载图片并提示用户保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!