|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-05-16 21:46 UTC] noodleyman at gmail dot com
Description: ------------ When using GetFile() as documented http://php.net/manual/en/directoryiterator.getsize.php if you run the function on a large file you get negative values which are wrong. I haven't got the exact file size that this happens at, but I have tested with files of 7GB and over, and always get the same result. tested using the function in the test script. Test script: --------------- function dirSize($directory) { $size = 0; foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){ $size+=$file->getSize(); } return $size; } Then ran function using input value of a directory with a single file of 8,510,398,464 bytes in size. Expected result: ---------------- 8310936 KB Actual result: -------------- -77674.63 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
Just confirming that I have also tested this using the code in the example page as linked to below and here are the results <?php $iterator = new DirectoryIterator(dirname(__FILE__)); foreach ($iterator as $fileinfo) { if ($fileinfo->isFile()) { echo $fileinfo->getFilename() . " " . $fileinfo->getSize() . "\n"; } } ?> on the same file, this returns a result of "-79538816"now using these functions to get a work around. function dos_filesize($fn) { if (is_file($fn)) return exec('FOR %A IN ("'.$fn.'") DO @ECHO %~zA'); else return '0'; } function dirSize($directory) { $size = 0; foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){ $size+=dos_filesize($file); } return $size; }