Jump to content

URL fopen with special characters


jamesm6162

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/219797-url-fopen-with-special-characters/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.