View Single Post
Old 09-26-2007, 05:57 AM  
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
:stoned PHP Guru - need ur help

I want to "Download' a file from a remote server with a PHP script.

I used this function below, but I need to enable the remote file opening option in php.ini to make it work. Let's say that I can't turn on this option for some reason. What else can I do to avoid this problem ? Is FTP functions my answer ?

Thanks

function download($file_source , $file_target) {
$rh = fopen ($file_source, 'rb');
$wh = fopen($file_target, 'wb' );
if ($rh===false || $wh=== false) {
return true;
}
while (!feof($rh )) {
if (fwrite($wh, fread( $rh, 1024)) === FALSE) {
// 'Download error: Cannot write to file ('.$file_target.')';
return true ;
}
}
fclose($rh);
fclose ($wh);
// No error
return false;
}
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote