note 126284 added to function.copy

From: Date: Wed, 28 Jul 2021 23:01:59 +0000
Subject: note 126284 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-216675@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 158.181.74.179) ---- Manual Page -- https://php.net/manual/en/function.copy.php Edit -- https://main.php.net/note/edit/126284 Del: integrated -- https://main.php.net/note/delete/126284/integrated Del: useless -- https://main.php.net/note/delete/126284/useless Del: bad code -- https://main.php.net/note/delete/126284/bad+code Del: spam -- https://main.php.net/note/delete/126284/spam Del: non-english -- https://main.php.net/note/delete/126284/non-english Del: in docs -- https://main.php.net/note/delete/126284/in+docs Del: other reasons-- https://main.php.net/note/delete/126284 Reject -- https://main.php.net/note/reject/126284 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216675) next »