Welcome Guest, Not a member yet? Register   Sign In
curl and php file downloading
#1

[eluser]peekk[/eluser]
Hi, I've got one problem.
I want to download remote image using curl. To do this i'm using these isntructions:

Code:
<?php
/*
This is usefull when you are downloading big files, as it
will prevent time out of the script :
*/
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....

$fp = fopen (dirname(__FILE__) . '/a.rss', 'w+');//This is the file where we save the information
$ch = curl_init('http://www.webdigity.com/rss.php');//Here is the file we are downloading
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

but it says that there is no such file or directory in (and this is weird) home/username/localhost/..
it gives the full system array to my localhost folder. Why?

When I'm doing this by:
Code:
file_put_contents('img.jpg',file_get_contents('http://example.com/img.jpg'));
It normally creates an image file in my main localhost folder, but i prefer to use curl. What's wrong?

Edit: ofc i know, that variable dirname(__FILE__) contains my full system path - but why? How can I do it same as in PHP without entering the full system path?


Regards!




Theme © iAndrew 2016 - Forum software by © MyBB