Edit report at https://bugs.php.net/bug.php?id=54758&edit=1

 ID:                 54758
 Comment by:         clicky at erebot dot net
 Reported by:        noodleyman at gmail dot com
 Summary:            GetSize() returns negative values for large file
                     sizes
 Status:             Open
 Type:               Bug
 Package:            Directory function related
 Operating System:   Windows Server 2008
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

This is a duplicate of bug #27792.
Short answer is: PHP does not support large files (>= 2GB) as of yet.


Previous Comments:
------------------------------------------------------------------------
[2011-05-17 11:21:38] noodleyman at gmail dot com

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;
}

------------------------------------------------------------------------
[2011-05-17 10:14:14] noodleyman at gmail dot com

the filesize() function also returns the same results as GetSize() for large 
files.

------------------------------------------------------------------------
[2011-05-17 10:11:35] noodleyman at gmail dot com

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"

------------------------------------------------------------------------
[2011-05-16 22:02:11] noodleyman at gmail dot com

just realised I typed the wrong function name in the description by mistake. it 
should read "When using GetSize()" not "When using GetFile()"

------------------------------------------------------------------------
[2011-05-16 21:46:57] 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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=54758&edit=1

Reply via email to