failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
I think preg_replace make more better sense as it will work with latest versions of the PHP as ereg_replace didn't worked for me being deprecated
$url = preg_replace("/ /", "%20", $url);
The only issue I can think of is spaces being in the url, most likely in the file name. All spaces in a url need to be converted to their proper encoding, which is %20.
If you have a file name like this:
"http://www.somewhere.com/images/img 1.jpg"
You would get the above error, but with this:
"http://www.somewhere.com/images/img%201.jpg"
You should have to problems.
Just use the str_replace()
to replace the spaces (" ") for their proper encoding ("%20")
It looks like this:
$url = str_replace(" ", "%20", $url);
For more information on the str_replace()
check out The PHP Manual.
I had the same problem, but it was solve by
$url = str_replace(" ", "%20", $url);
Thanks Cello_Guy for the post.