Get File Size using php
The following PHP code snippet used to Get File Size in B/KB/MB/GB/TB.
Code:
The following PHP code snippet used to Get File Size in B/KB/MB/GB/TB.
Code:
<?php /* * @param string $file Filepath * @param int $digits Digits to display * @return string|bool Size (KB, MB, GB, TB) or boolean */ function findFilesize($file,$digits = 2) { if (is_file($file)) { $filePath = $file; if (!realpath($filePath)) { $filePath = $_SERVER["DOCUMENT_ROOT"].$filePath; } $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; } ?>
0 comments:
Post a Comment
Share your thoughts here...