Last active
August 29, 2015 14:17
-
-
Save mattvot/877c518f5545b2844433 to your computer and use it in GitHub Desktop.
Filesize method that works with files >2GB on 32bit PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filesize method that works with files >2GB on 32bit PHP | |
* | |
* @link http://php.net/manual/en/function.filesize.php#113457 | |
* @param string $file Path to file | |
* @return int|float Size of file | |
*/ | |
function realFileSize($file) | |
{ | |
$fp = fopen($file, 'r'); | |
$pos = 0; | |
$size = 1073741824; | |
fseek($fp, 0, SEEK_SET); | |
while ($size > 1) | |
{ | |
fseek($fp, $size, SEEK_CUR); | |
if (fgetc($fp) === false) | |
{ | |
fseek($fp, -$size, SEEK_CUR); | |
$size = (int)($size / 2); | |
} | |
else | |
{ | |
fseek($fp, -1, SEEK_CUR); | |
$pos += $size; | |
} | |
} | |
while (fgetc($fp) !== false) $pos++; | |
fclose($fp); | |
return $pos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment