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
Groucho
Forum Newbie
Posts: 4 Joined: Thu Sep 16, 2004 2:32 pm
Post
by Groucho » Thu Sep 16, 2004 2:52 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Sep 16, 2004 2:57 pm
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 » Thu Sep 16, 2004 3:20 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Sep 16, 2004 3:25 pm
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 » Thu Sep 16, 2004 3:35 pm
Solved using
str_replace(" ", "%20", $file); (encoding all it don't work... boh)
Tnx
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Sep 16, 2004 3:38 pm
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 » Thu Sep 16, 2004 3:48 pm
Code: Select all
...
$file = urlencode($_GETї"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);
...