note 60719 deleted from function.fopen by betz
| From: | betz@php.net | Date: | Sun, 15 Jan 2006 10:29:55 +0000 |
| Subject: | note 60719 deleted from function.fopen by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101791@lists.php.net to get a copy of this message | ||
Note Submitter: flobee
----
download: i need a function to simulate a "wget url" and do not buffer the data in the
memory to avoid thouse problems on large files:
<?php
function download($file_source, $file_target) {
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'wb');
if ($rh===false || $wh===false) {
// error reading or opening file
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;
}
?>