Advertisement
Virajsinh

get file size funcation in php

Sep 13th, 2021
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. function Size($path)
  2. {
  3.     $bytes = sprintf('%u', filesize($path));
  4.  
  5.     if ($bytes > 0)
  6.     {
  7.         $unit = intval(log($bytes, 1024));
  8.         $units = array('B', 'KB', 'MB', 'GB');
  9.  
  10.         if (array_key_exists($unit, $units) === true)
  11.         {
  12.             return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]);
  13.         }
  14.     }
  15.  
  16.     return $bytes;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement