0

让用户单击下载按钮然后自动获取图像文件然后将其下载到他们的通用下载文件夹或提示他们保存它的最佳方法是什么?

我尝试了以下但没有成功:

  $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);

等等,还是我要解决这一切都错了(可能)

谢谢

4

2 回答 2

5

在回显数据之前:

header('Content-Disposition: attachment; filename=save_as_name.jpg');

然后

echo file_get_contents("http://...");
于 2012-09-18T22:57:08.060 回答
0
header('Content-Disposition: attachment; filename="exmaple.jpg"');
header('Content-Type: application/octet-stream'); // (or a MIME type like "image/jpeg")

echo $file_content;
于 2012-09-18T22:59:35.587 回答