TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Correcting negative filesize() bug for larger files (http://www.talkphp.com/general/5333-correcting-negative-filesize-bug-larger-files.html)

skibbli 03-06-2010 08:12 PM

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 $b $b $b $b;
$kb $b 1024;
$mb $kb 1024;
$gb $mb 1024;
if ( 
$mb >= 1024 ) echo " " round($gb2) . " gb";
if ( 
$kb >= 1024 && $gb 1) echo " " round($mb2) . " mb";
if ( 
$b >= 1024 && $mb ) echo " " round($kb2) . " kb";
if ( 
$b 1024 ) echo " " $b " b";
echo 
"<br>";
}
}
closedir($handle);
?>



All times are GMT. The time now is 02:19 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0