什么是最好的让用户点击下载按钮,然后自动获取图像文件,然后将其下载到他们的通用下载文件夹或提示他们保存?
我尝试了以下但没有成功:
$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);
Run Code Online (Sandbox Code Playgroud)
或者我是否会这样做(可能)
谢谢
在回显数据之前:
header('Content-Disposition: attachment; filename=save_as_name.jpg');
Run Code Online (Sandbox Code Playgroud)
然后
echo file_get_contents("http://...");
Run Code Online (Sandbox Code Playgroud)