I am trying to get images from a remote server using file_get_contents
. A URL to an image may contain spaces and/or special characters like ý, á, í, etc and when it does the operation fails with a HTTP code 400 - Bad Request. If I try to encode the url (or segments of that URL), using urlencode
or rawurlencode
, I get a 404.
When the image URL does not contain spaces nor special chars it is downloaded without problems.
I have a hunch that this has got something to do with encoding but I just can't figure it out. Is there an encoding option I'm missing? Is there a header that must be set for the request?