php how to get web image size in kb?

前端 未结 7 970
迷失自我
迷失自我 2020-12-31 01:40

php how to get web image size in kb?

getimagesize only get the width and height.

and filesize caused waring.



        
7条回答
  •  清歌不尽
    2020-12-31 02:00

    You can get the file size by using the get_headers() function. Use below code:

        $image = get_headers($url, 1);
        $bytes = $image["Content-Length"];
        $mb = $bytes/(1024 * 1024);
        echo number_format($mb,2) . " MB";
    

提交回复
热议问题