php how to get web image size in kb?

2019-02-06 03:26发布

php how to get web image size in kb?

getimagesize only get the width and height.

and filesize caused waring.

$imgsize=filesize("http://static.adzerk.net/Advertisers/2564.jpg");
echo $imgsize;

Warning: filesize() [function.filesize]: stat failed for http://static.adzerk.net/Advertisers/2564.jpg

Is there any other way to get a web image size in kb?

7条回答
Deceive 欺骗
2楼-- · 2019-02-06 04:06

Short of doing a complete HTTP request, there is no easy way:

$img = get_headers("http://static.adzerk.net/Advertisers/2564.jpg", 1);
print $img["Content-Length"];

You can likely utilize cURL however to send a lighter HEAD request instead.

查看更多
登录 后发表回答