Doh can’t edit title it seems on these forums. Correct Title: WGET + Curl Streaming.
I’m using the following function to try and grab files from remote hosts:
function wGET_file($url, $path) {
$fp = fopen($path, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
}
However, the file is always an empty file with 0 size. The link is correct and everything just the file is always empty.
Any ideas why?
Thanks,
Desk_man
This appears to work fine, it needs some work though.
<?php
error_reporting(-1);
ini_set('display_errors', true);
function curl_save_file($url, $file){
$fp = fopen($file, 'w');
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FILE => $fp
));
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
Thanks for your help.
I just gave it a quick try but i’m having the same issue with the file being empty and 0 bytes in size.
Now i looked alittle further and tried a file on a different server and it worked. Strange but hazar!
Much appreciated.
Cups
May 14, 2011, 2:06pm
4
If you have the correct permissions you could always just use wget, or get PHP to do it for you with exec(), or use cron to call wget . I guess you are aware of it seeing as how you named your function but maybe others aren’t.