dongqi6486 2012-09-18 22:55
浏览 47
已采纳

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 or am i going about this all wrong (probably)

thanks

  • 写回答

2条回答 默认 最新

  • drn34916 2012-09-18 22:57
    关注

    Before you echo the data:

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

    Then

    echo file_get_contents("http://...");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?