Php get KB image size

I was googleing, but all I get is getimagesize and filesize.
getimagesize dosent only gets KB size in width and height, which is not what they need.
filesize give me a warning message : filesize () [function.filesize]: stat failed to execute
the file in question is 51kb.jpg file

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

does not work,

how to do it?

+7
php filesize
source share
6 answers

You cannot get the file size of deleted items, either specify the relative path on your system, or execute file_get_contents() to get the content first, So instead of http: //, do a filesize('/path/to/local/system') . Make sure it is read by php process

+7
source share

You cannot search the file size of a remote file like this. It is designed to view local file files.

For example...

 $imgsize = filesize( '/home/projects/site/1.jpg' ); 
+4
source share

filesize() is the function to use. This may be unsuccessful because

  • You are trying to get a web address and URL wrappers may not be included
  • This URL is not valid.

If you are trying to run filesize() in a local file, specify the path to the file system, not some web URL.

+1
source share

Or you can also do something like:

 $header = get_headers($url); foreach ($header as $head) { if (preg_match('/Content-Length: /', $head)) { $size = substr($head, 15); } } 
+1
source share

filesize takes the file name as an argument, not a URL, and returns the file size in bytes. You can split the return value with 1024 to get the size in KB.

0
source share

I had the same problem that I solved like this. I don't know how optimal this is, but it works for me:

 getimagesize("http://localhost/projects/site/schwe/user/1/1.jpg"); $file_size = $file[0]*$file[1]*$file["bits"]; 
0
source share

All Articles