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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.