
PHP command file_get_contents() failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found.
The PHP command file_get_contents(url) requires an encoded URL as input parameter. If you use urlencode(url) it will replace all non-alphanumeric characters except - _ and . in the URL with its % two hex digits equivalent. Remember, spaces are encoded as plus (+) signs. It is better to use the function rawurlencode() which also transforms the plus (+) sign.
Above a valid encoded URL, you also have to ensure that the location actually exists. When the requested URL is created on the fly; another often heard error is to use the PHP command sleep(x) to make sure that your script is not faster than the creation of the actual file on the server.
Other file_get_contents warnings such as the failed to open stream: HTTP request failed! HTTP/1.1 406 Not Acceptable error is often caused by server side settings such as the mod_security web application. It is a sort of firewall which allows the server to keep track of unwanted attacks, HTTP traffic and other monitoring functionality.
Would you like to comment?
Fields with * are obligatory.


