jamesm6162 Posted November 25, 2010 Share Posted November 25, 2010 Hi all I need to retrieve a remote file and store it on my server. There are several methods to do this, but all of them fail when the URL contains special characters such as spaces. Consider the following URL: 'http://www.somedomain.com/Images/Products/MyProduct (Large).jpg' Assuming the allow_url_fopen directive is set to "on" in the php.ini, one can normally call: $url = ... $handle = fopen($url); to access the file. However, the space in the filename causes a Bad HTTP Request (Response 400). Using urlencode to encode the url doesn't solve the problem either, as all forward slashes and the colon after the protocol get escaped, and fopen doesn't recognize it as a URL. Besides manually replacing all the characters in the URL that are not colons or forward slashes (and are considered 'special'), can anyone give me any other solutions to make this work? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219797-url-fopen-with-special-characters/ Share on other sites More sharing options...
trq Posted November 25, 2010 Share Posted November 25, 2010 but all of them fail when the URL contains special characters such as spaces Spaces are not 'special', they are invalid. Quote Link to comment https://forums.phpfreaks.com/topic/219797-url-fopen-with-special-characters/#findComment-1139447 Share on other sites More sharing options...
aabid Posted November 25, 2010 Share Posted November 25, 2010 Try adding %20 instead of space, it should work Quote Link to comment https://forums.phpfreaks.com/topic/219797-url-fopen-with-special-characters/#findComment-1139452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.