M
M
Mikhail Vasiltsev2018-03-11 23:03:22
PHP
Mikhail Vasiltsev, 2018-03-11 23:03:22

How to find out the size of an image using PHP without loading it?

Hello. I need to calculate the number of images and their total size for each page. Everything is clear with the quantity, but I consider the size in the cycle as follows:

$img= file_get_contents($url);
echo strlen($img) / 1024 . ' КБ';

And so I get the size of each picture in kilobytes. But this one is bad because in order to determine the size, the picture needs to be downloaded via file_get_contents and this takes traffic, and since there are sometimes more than 30 pictures on the page and all this is sorted in a loop, the script will run for a long time.
The question is, in fact, is there a way, having the url-s of the images in hand, to find out the weight of the pictures, without making them load?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-03-11
@mihail430899

php.net/manual/en/function.getimagesize.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question