I use this script to get an overview of how many files I have on my website, what type they are and what size:
<?
$typer = array( "php", "pdf", "htm", "zip", "jpg", "avi" ); //add more types here.
foreach( $typer as $type ) {
$bytes=0;
$filer=0;
tree( "./", $type, 3, "" );
$kb = $bytes/1024;
$mb=$kb/1024;
$gb=$mb/1024;
$size[$type] = $bytes;
$files[$type] = $filer;
}
$filestotal=0;
$bytestotal=0;
foreach( $size as $type => $bytes) {
echo "<b>$files[$type]</b>" . " " . "." .$type . "-files " . " " . "total size " . " " . number_format($bytes, 0, ',', '.') . " " . "bytes" . "<br />";
$filestotal += $files[$type];
$bytestotal += $bytes;
}
function tree( $path, $type ) {
global $bytes, $filer;
$d = dir($path);
while (false !== ($entry = $d->read())) {
$etdir = is_dir($path.$entry);
if( $entry != "." && $entry != ".." && $entry != "" ) {
$path_parts = pathinfo($entry);
if( strstr($type, $path_parts["extension"]) || $type=="*" && !$etdir ) {
$bytes += filesize($path.$entry);
$filer++;
}
if( $etdir ) {
tree( $path.$entry."/", $type);
}
}
}
$d->close();
}
?>
The script shows the size of the files in bytes but I would really like to get the size in megabytes (M😎. What do I need to change in order to get that? So that eg. 120898 bytes is shown as 0.12 mb or 3202148 bytes as 3.20 mb? Anyone?
Thanks in advance.