help with file size with php
I have a working directoery lister that I was able to adapt some code to but I am getting frustrated in a atempt to get the file sizes to be more precise.
Php is not my strongest thing-lol
this is used in a file to get file sizes:
PHP Code:
$size=number_format(filesize($dirArray[$index]));
I found this code but the array in the first example is messing me up.
PHP Code:
[COLOR="#FF0000"]function getFilesize($file,$digits = 2) {
if (is_file($file)) {
$filePath = $file;
if (!realpath($filePath)) {
$filePath = $_SERVER["DOCUMENT_ROOT"].$filePath;
}[/COLOR]
$fileSize = filesize($filePath);
$sizes = array("TB","GB","MB","KB","B");
$total = count($sizes);
while ($total-- && $fileSize > 1024) {
$fileSize /= 1024;
}
return round($fileSize, $digits)." ".$sizes[$total];
}
return false;
}
I tried first to remove the red highlighted part that did not work.
I tried this too and it did not work
PHP Code:
$fileSize = filesize($filePath);
$sizes = array("TB","GB","MB","KB","B");
$total = count($sizes);
while ($total-- && $fileSize > 1024) {
$fileSize /= 1024;
}
return round($fileSize, $digits,$dirArray[$index])." ".$sizes[$total];
}
return false;
}
Any hint where I should be going with this?
the original script shows only byte size.which can be large for some stuff-lol
If needed,I can put up a link to a text file of the working script.
thanks in advance