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?
You can get the file size by using the get_headers() function. Use below code:
Here is a good link regarding filesize()
You cannot use filesize() to retrieve remote file information. It must first be downloaded or determined by another method
Using Curl here is a good method:
Tutorial
Not sure about using
filesize()
for remote files, but there are good snippets on php.net though about using cURL.http://www.php.net/manual/en/function.filesize.php#92462
You can use also this function
That sounds like a permissions issue because filesize() should work just fine.
Here is an example:
Make sure the permissions are set correctly on the image and that the path is also correct. You will need to apply some math to convert from bytes to KB but after doing that you should be in good shape!