View Single Post
Old 02-04-2009, 06:27 PM  
Juicy D. Links
So Fucking Banned
 
Industry Role:
Join Date: Apr 2001
Location: N.Y. -Long Island --
Posts: 122,992
Code:
  
function formatbytes($file, $type)   
{   
    switch($type){   
        case "KB":   
            $filesize = filesize($file) * .0009765625; // bytes to KB   
        break;   
        case "MB":   
            $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB   
        break;   
        case "GB":   
            $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB   
        break;   
    }   
    if($filesize <= 0){   
        return $filesize = 'unknown file size';}   
    else{return round($filesize, 2).' '.$type;}   
}

Code:
// USAGE   
echo formatbytes("$_SERVER[DOCUMENT_ROOT]/images/large_picture.jpg", "MB");   
// would display the file size in MB

Last edited by Juicy D. Links; 02-04-2009 at 06:28 PM..
Juicy D. Links is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote