Virajsinh

Get File Size Using PHP

Jan 9th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. function format_size($size) {
  2.   $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
  3.   if ($size == 0) { return('n/a'); } else {
  4.       return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
  5.   }
  6.  
  7.   function getFileSize($url)
  8.   {
  9.     $ch = curl_init($url);
  10.  
  11.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  12.     curl_setopt($ch, CURLOPT_HEADER, TRUE);
  13.     curl_setopt($ch, CURLOPT_NOBODY, TRUE);
  14.  
  15.     $data = curl_exec($ch);
  16.     $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
  17.  
  18.     curl_close($ch);
  19.     return $size;
  20. }
Add Comment
Please, Sign In to add comment