How can I the size of an image file from the URL?

后端 未结 5 2054
天命终不由人
天命终不由人 2020-12-16 20:56

Images and script are hosted on the same account (one site), but we know only the URL of the image.

$image = \"http://example.com/images/full-1091.jpg\"
         


        
5条回答
  •  [愿得一人]
    2020-12-16 21:39

    Use filesize function like this:

    echo filesize($filename) . ' bytes';
    

    You can also format the unit of the size with this function:

    function format_size($size) {
          $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
          if ($size == 0) { return('n/a'); } else {
          return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
    }
    

提交回复
热议问题