Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php how to get web image size in kb?

Tags:

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?

like image 260
fish man Avatar asked Jun 07 '11 23:06

fish man


People also ask

How to get size of an image in php?

The getimagesize() function in PHP is an inbuilt function which is used to get the size of an image. This function accepts the filename as a parameter and determines the image size and returns the dimensions with the file type and height/width of image.

How do I scale an image in PHP?

The imagescale() function is an inbuilt function in PHP which is used to scale an image using the given new width and height. Parameters: This function accepts four parameters as mentioned above and described below: $image: It is returned by one of the image creation functions, such as imagecreatetruecolor().

What are the functions to be used to get the image properties size width and height?

The imagesx() and imagesy() are used to extract the width and height of the images respectively.


2 Answers

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.

like image 140
mario Avatar answered Sep 16 '22 12:09

mario


<?php
$file_size = filesize($_SERVER['DOCUMENT_ROOT']."/Advertisers/2564.jpg"); // Get file size in bytes
$file_size = $file_size / 1024; // Get file size in KB
echo $file_size; // Echo file size
?>
like image 36
Morgan Delaney Avatar answered Sep 16 '22 12:09

Morgan Delaney