Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php get the KB size of an image

i've been googleing but all i get is getimagesize and filesize.
getimagesize dosent get the KB size just width and height which is not what im looking for.
filesize give me the message Warning: filesize() [function.filesize]: stat failed for
the file in question is 51kb .jpg file

$imgsize=filesize("http://localhost/projects/site/schwe/user/1/1.jpg");

does not work,

how do i accomplish this?

like image 694
Macao Avatar asked Sep 27 '10 15:09

Macao


People also ask

How can I get image resolution in PHP?

PHP | imageresolution() Function. The imageresolution() function is an inbuilt function in PHP which is used to set and return the resolution of an image in DPI (dots per inch). If none of the optional parameters is given, the current resolution is returned as an indexed array.

How can we get the properties of an image in PHP?

The Imagick::getImageProperties() function is an inbuilt function in PHP which is used to get the image properties.


2 Answers

You cannot get file size of remote elements, either give a relative path on your system OR do a file_get_contents() to get contents first . Thus, instead of http:// , do a filesize('/path/to/local/system') . Make sure its readable by php process

like image 142
Stewie Avatar answered Nov 01 '22 05:11

Stewie


You can't look up the filesize of a remote file like that. It is meant for looking at the filesize of local files.

For instance...

$imgsize = filesize( '/home/projects/site/1.jpg' );
like image 40
BBonifield Avatar answered Nov 01 '22 04:11

BBonifield