cUrl and spaces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Groucho
Forum Newbie
Posts: 4
Joined: Thu Sep 16, 2004 2:32 pm

cUrl and spaces

Post by Groucho »

Hi folks,

I have a problem with this code:

Code: Select all

<?
...
//	$file= urlencode($file); 
	$ch = curl_init("http://www.site.com/");
	curl_setopt ($ch, CURLOPT_URL, $file);
	curl_setopt ($ch, CURLOPT_REFERER, "http://www.site.com/");
	curl_exec ($ch);
	curl_close ($ch);
?>
For example, when i try to download curl.php?file=Whatever_File with spaces.zip

I get:

Not Found
The requested URL /Whatever_File was not found on this server.
...


pls help me :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make sure the url parameter is url encoded. for example:

Code: Select all

curl.php?file=some%20file%20name.zip
Groucho
Forum Newbie
Posts: 4
Joined: Thu Sep 16, 2004 2:32 pm

Post by Groucho »

Umh,
If i encode the whole string script don't work but if i replace only space with %20 it seems to work.

oO

P.S. the true URL is as: cURL?file=http://www.site.com/file with spaces.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

url parameters and their values must be urlencoded.. it should be this:

Code: Select all

curl.php?file=http%3A%2F%2Fwww.site.com%2Ffile+with+spaces.php
Groucho
Forum Newbie
Posts: 4
Joined: Thu Sep 16, 2004 2:32 pm

Post by Groucho »

Solved using str_replace(" ", "%20", $file); (encoding all it don't work... boh)

Tnx :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where did you encode it? if it's in the code path doing the request, that's the wrong place.
Groucho
Forum Newbie
Posts: 4
Joined: Thu Sep 16, 2004 2:32 pm

Post by Groucho »

Code: Select all

...
	$file = urlencode($_GET&#1111;"file"]); //Don't work
//	$file = str_replace(" ", "%20", $file); Work

	$ch = curl_init("http://www.site.com/"); 
	curl_setopt ($ch, CURLOPT_URL, $file); 
	curl_setopt ($ch, CURLOPT_REFERER, "http://www.site.com/"); 
	curl_exec ($ch); 
	curl_close ($ch); 
...
Post Reply