note 126284 rejected from function.copy by cmb

From: Date: Thu, 29 Jul 2021 09:24:20 +0000
Subject: note 126284 rejected from function.copy by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216678@lists.php.net to get a copy of this message
Note Submitter: stanislav dot eckert at vizson dot de ---- Note that functions in PHP, like copy() and stream_copy_to_stream() cannot copy files larger than 4 GiB correctly, even on 64-bit systems with 64-bit builds of PHP (even with PHP 8). The copied file will have the same size as the original file, but the file content will repeat after every 4 GiB. Do not use copy() at all. Copy files instead manually with fopen() and fread() / fwrite() or use file_put_contents() with FILE_APPEND parameter. Example: <?php function copyFile($src, $dest) { $bufferLen = 1048576; // 1 MiB $ret = 0; $fin = fopen($src, "rb"); $fout = fopen($dest, "w"); while (!feof($fin)) { $ret += fwrite($fout, fread($fin, $bufferLen)); } fclose($fin); fclose($fout); return $ret; } ?>

« previous php.notes (#216678) next »