file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

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:


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?


The following answer worked for me: PHP file_get_contents 500 Internal Server error

$opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n")); $context = stream_context_create($opts); $header = file_get_contents('https://www.example.com', FALSE, $context);


  • How to create two column output from a single column
  • How can I get the choice “H2” back in the H2 consol?
  • How can I restyle a word when rendering a pdf with pdf.js?
  • what makes a request a new request in asp.net C#
  • Approximate Order-Preserving Huffman Code
  • System.InvalidCastException: Specified cast is not valid
  • Unable to decode certificate at client new X509Certificate2()
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Rails Find when some params will be blank
  • MongoError: Incorrect arguments
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Python urlparse: small issue
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • Read a local file using javascript
  • Highlight one bar in a series in highcharts?
  • FileReader+canvas image loading problem
  • Lost migrations and Azure database is now out of sync
  • Is there any way to access browser form field suggestions from JavaScript?
  • Android screen density dpi vs ppi
  • Dynamically accessing properties of knockoutjs observable array
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • script to move all files from one location to another location
  • WinForms: two way TextBox problem
  • Can I make an Android app that runs a web view in Chrome 39?
  • Release, debug version and Authorization Google?
  • Circular dependency while pushing http interceptor
  • Is there a mandatory requirement to switch app.yaml?
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • AngularJs get employee from factory
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • python draw pie shapes with colour filled
  • JaxB to read class hierarchy
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF