Page 1 of 1

cUrl and spaces

Posted: Thu Sep 16, 2004 2:52 pm
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 :(

Posted: Thu Sep 16, 2004 2:57 pm
by feyd
make sure the url parameter is url encoded. for example:

Code: Select all

curl.php?file=some%20file%20name.zip

Posted: Thu Sep 16, 2004 3:20 pm
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

Posted: Thu Sep 16, 2004 3:25 pm
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

Posted: Thu Sep 16, 2004 3:35 pm
by Groucho
Solved using str_replace(" ", "%20", $file); (encoding all it don't work... boh)

Tnx :D

Posted: Thu Sep 16, 2004 3:38 pm
by feyd
where did you encode it? if it's in the code path doing the request, that's the wrong place.

Posted: Thu Sep 16, 2004 3:48 pm
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); 
...