Page 1 of 1

How do I check the filesize of a stored image?

Posted: Mon Jun 13, 2016 4:48 pm
by simonmlewis
I need to add up all the images we have on a homepage, from the admin screen.
To do that, I want to get the filesize of each "banner" type image, and then at the bottom, show the filesize overall.

Sounds easy, but it won't let me even get one file size.

I can do it when I run an upload with the ['tmp'] format, but I want to get the filesize like this:

Code: Select all

$path = "/images/pages/$row->image";
echo filesize("$path");
And all I get is this error:

[text]Warning: filesize(): stat failed for /images/pages/97242645m27g.jpg in C:\xampp\phpMyAdmin\site-wide\includes\a_home.inc on line 767[/text]

Re: How do I check the filesize of a stored image?

Posted: Mon Jun 13, 2016 7:54 pm
by Christopher
Are you sure your file path is right. Usually /images is in the document root directory.

Re: How do I check the filesize of a stored image?

Posted: Tue Jun 14, 2016 1:47 am
by simonmlewis
If I put that string into a <img> tag, I get the image.

Re: How do I check the filesize of a stored image?

Posted: Tue Jun 14, 2016 7:12 pm
by Christopher
That's because it's the path relative to the domain name in the URL. The filesize() function wants the absolute path in the file system of the server. Those are two very different things. It should be $path = "/path/to/document/root/images/pages/{$row->image}";

Re: How do I check the filesize of a stored image?

Posted: Wed Jun 15, 2016 1:49 am
by simonmlewis
Oh ok.
So how do you test it on a Windows PC, and i guess on a server I need to find out what the "path" is.
Or is there a PHP script that can help me identify that?

Re: How do I check the filesize of a stored image?

Posted: Wed Jun 15, 2016 4:01 pm
by Christopher
It's document root, so php.ini or use phpinfo() ?