0

The code below(learned from Save image from url with curl PHP) works fine when try to grap image from internet. But when come to the url below, I only got a "test.jpg" which is actually a 404 error page("test.jpg" could be opened by notepad). PS: And i could open the url with browser and could see the image

$url = 'https://spthumbnails.5min.com/10368406/518420256_c_570_411.jpg';
$saveto="test.jpg";
grab_image($url,$saveto);
function grab_image($url,$saveto){
   $ch = curl_init ($url);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
   $raw=curl_exec($ch);
   curl_close ($ch);
   if(file_exists($saveto)){
      unlink($saveto);
   }
   $fp = fopen($saveto,'x');
   fwrite($fp, $raw);
   fclose($fp);
}
Community
  • 1
  • 1
weblen
  • 149
  • 1
  • 2
  • 9
  • 1
    What do you mean by "could get all images except for this url"? What is the problem? Is there an error? Is the output not what you want? – Dettorer Dec 30 '14 at 13:45
  • 1
    Try to open this url in your browser. I have got an error `The Page Cannot Be Displayed` – fiction Dec 30 '14 at 13:45
  • make sure the image has set proper type properties... – Grasper Dec 30 '14 at 13:45
  • There's nothing "special" about that URL, no. What is the server's response when you make this request? For me it's a 404, which would explain a lot. – David Dec 30 '14 at 13:46
  • This is so wired.I could get the image from the browser. – weblen Dec 30 '14 at 13:52

0 Answers0