03-06-2010, 08:12 PM
|
#1 (permalink)
|
|
bajingo
Join Date: Feb 2010
Posts: 11
Thanks: 2
|
Correcting negative filesize() bug for larger files
As you may know, PHP 5.2.13 has an issue with determining the size of a large file. The number of bytes will be displayed as a negative if the file size is too large. I've come up with a very simple fix and made a way to display the files in a list with the size as it should be seen (eg if the size is within the range of kb/mb/gb
PHP Code:
<?php $handle=opendir("."); while (($file = readdir($handle))!==false) { if ( !in_array($file, array(".", "..", "index.php")) && is_file($file) ) { echo "<a href='$file'>$file</a>"; $b = filesize($file); if ( $b < 0 ) $b = $b - $b - $b; $kb = $b / 1024; $mb = $kb / 1024; $gb = $mb / 1024; if ( $mb >= 1024 ) echo " " . round($gb, 2) . " gb"; if ( $kb >= 1024 && $gb < 1) echo " " . round($mb, 2) . " mb"; if ( $b >= 1024 && $mb < 1 ) echo " " . round($kb, 2) . " kb"; if ( $b < 1024 ) echo " " . $b . " b"; echo "<br>"; } } closedir($handle); ?>
Last edited by skibbli : 03-22-2010 at 04:47 AM.
|
|
|
|