I'm retrieving and saving images from a external source to my webserver by URL's. Unfortaley sometimes I get the following error: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error.
When I visit the given url with my browser the image is shown and valid. The url:
http://****.com/00/s/NTgwWDcyNg==/z/7LEAAMXQVT9TCcxx/$_85.JPG
The code which I use:
$opts = array('http'=>array('header' => "User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1\r\n", 'timeout' => "360"));
$context = stream_context_create($opts);
$imageString = file_get_contents(urldecode(urlencode($filename)), false, $context);
$save = file_put_contents(dirname(dirname(__FILE__)) . '/tmp/' . $id . '_' . $sequenceNumber . '.jpg', $imageString);
Anyone has a idea why I get a 500 error?