Portfolio
Scripts and Websites I've made using PHP and MySQL mainly.
Snippets
Code snippets and mini tutorials
Contact
Contact me if you have any questions or queries
Home / Snippets / file_size
This section is new and undergoing snippet addition, as of 13/6/11
Example Usage:
This section is new and undergoing snippet addition, as of 13/6/11
File Size
function getFileSize($file)
{
if(file_exists($file))
{
$sizeInBytes = filesize($file);
if($sizeInBytes > 1073741824){$size = round($sizeInBytes / 1073741824, 2); $size .= " Gigabytes";}
elseif($sizeInBytes > 1048576){$size = round($sizeInBytes / 1048576, 2); $size .= " Megabytes";}
elseif($sizeInBytes > 1024){$size = round($sizeInBytes / 1024, 2); $size .= " Kilobytes";}
else{$size = round($sizeInBytes, 2); $size .= " Bytes";}
return $size;
}
else
{
return "File not found";
}
}
Example Usage:
echo "File Size (setup.EXE): " . getFileSize('setup.EXE') . "
";
echo "File Size (phpForms.php): " . getFileSize('phpForms.php') . "
";
echo "File Size (test.php): " . getFileSize(__FILE__) . "
";
Comments
No Comments Have Been Made


