Re: file_get_contents urlencode spaces: yeah right?
| From: | Micah Gersten | Date: | Mon, 10 Nov 2008 23:07:20 +0000 |
| Subject: | Re: file_get_contents urlencode spaces: yeah right? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283198@lists.php.net to get a copy of this message | ||
Dee Ayy wrote:
> PHP Version 5.1.6
> $contents =
> file_get_contents("http://user:pass@domain.com/some/path/htmlfile.html"); //WORKS
> $contents =
> file_get_contents("http://user:pass@domain.com/some/path/htmlfile
> with spaces.html"); //FAILS(1)
> $contents =
> file_get_contents("http://user:pass@domain.com/some/path/nonhtmlfile.ext"); //WORKS
> $contents =
> file_get_contents("http://user:pass@domain.com/some/path/nonhtmlfile
> with spaces.ext"); //FAILS(2)
> $contents =
> file_get_contents(urlencode("http://user:pass@domain.com/some/path/eitherfile
> with spaces.ext")); //FAILS BUT I DON'T REALLY CARE
> $contents =
> file_get_contents(urlencode("http://user:pass@domain.com/some/path/eitherfilenospaces.ext")); //FAILS
> BUT I DON'T REALLY CARE
> $contents =
> file_get_contents("http://user:pass@domain.com/some/path/".urlencode("eitherfile
> with spaces.ext")); //FAILS WTF(1)
> $contents =
> file_get_contents("http://user:pass@domain.com/some/path/eitherfile+with+spaces.ext"); //FAILS
> WTF(2)
>
> <br />
> <b>Warning</b>:
> file_get_contents(http://...@domain.com/some/path/eitherfile+with+spaces.ext)
> [<a href='function.file-get-contents'>function.file-get-contents</a>]:
> failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in
> <b>/the/script/index.php</b> on line <b>(the file_get_contents
> line)</b><br />
>
> Yes, the files are there.
>
> file_get_contents docs:
> Note: If you're opening a URI with special characters, such as spaces,
> you need to encode the URI with urlencode().
>
> WTF?!?!
> How do I get FAILS(1) and FAILS(2) to work, in light of FAILS WTF(1)
> and FAILS WTF(2)?
>
>
Have you tried to output the result of urlencode and paste the whole
thing in a browser to make sure that it works?
Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com