Re: file_get_contents urlencode spaces: yeah right?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dee Ayy wrote:
> PHP Version 5.1.6
> $contents = file_get_contents("http://user:pass@xxxxxxxxxx/some/path/htmlfile.html";);						//WORKS
> $contents = file_get_contents("http://user:pass@xxxxxxxxxx/some/path/htmlfile
> with spaces.html");				//FAILS(1)
> $contents = file_get_contents("http://user:pass@xxxxxxxxxx/some/path/nonhtmlfile.ext";);						//WORKS
> $contents = file_get_contents("http://user:pass@xxxxxxxxxx/some/path/nonhtmlfile
> with spaces.ext");			//FAILS(2)
> $contents = file_get_contents(urlencode("http://user:pass@xxxxxxxxxx/some/path/eitherfile
> with spaces.ext"));	//FAILS BUT I DON'T REALLY CARE
> $contents = file_get_contents(urlencode("http://user:pass@xxxxxxxxxx/some/path/eitherfilenospaces.ext";));		//FAILS
> BUT I DON'T REALLY CARE
> $contents = file_get_contents("http://user:pass@xxxxxxxxxx/some/path/".urlencode("eitherfile
> with spaces.ext"));	//FAILS WTF(1)
> $contents = file_get_contents("http://user:pass@xxxxxxxxxx/some/path/eitherfile+with+spaces.ext";);			//FAILS
> WTF(2)
> 
> <br />
> <b>Warning</b>:
> file_get_contents(http://...@xxxxxxxxxx/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)?
> 

Try replacing the '+' signs with %20.  Worked for me.

I had the same results as you on my server.  The only fix I found was to replace the + with %20.

Maybe the user agent & server are doing something special that file_get_contents() & server are not doing.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux