title: How to grap this specific url?
body: <p>The code below(learned from <a href="https://stackoverflow.com/questions/6476212/save-image-from-url-with-curl-php">Save image from url with curl PHP</a>) 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. Thanks to Mike,Problem solved and code updated.</p>
  
  <pre><code>$url = 'https://spthumbnails.5min.com/10368406/518420256_c_570_411.jpg';
  $reffer="http://www.sohu.com";
  $user_agent="Baiduspider+(+http://www.baidu.com/search/spider.htm)";
  $saveto="test.jpg";
  grab_image($url,$saveto);
  
  function grab_image($url,$saveto,$reffer,$user_agent){
      $ch = curl_init ($url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
      curl_setopt($ch,CURLOPT_REFERER,$reffer);
      curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
      $raw=curl_exec($ch);
      curl_close ($ch);
      $fp = fopen($saveto,'w');
      fwrite($fp, $raw);
      fclose($fp);
  }
  </code></pre>