djfox Posted September 7, 2007 Share Posted September 7, 2007 I`ve been toying around with the function getimagesize() and looking over other sites and http://www.php.net/getimagesize and got the width and height in pixels, and finally managed to get the file type (jpg, png, gif, etc). But how do I get the actual file size? (Ie, the part that says ###KB or ###MB) Quote Link to comment Share on other sites More sharing options...
trq Posted September 7, 2007 Share Posted September 7, 2007 filesize(). Quote Link to comment Share on other sites More sharing options...
djfox Posted September 7, 2007 Author Share Posted September 7, 2007 Can smeone double check my code on this: <?php $filename = '$rows[3]'; echo filesize($filename) . ' bytes'; ?> I get an error and am not sure if I messed the code up somewhere. Quote Link to comment Share on other sites More sharing options...
trq Posted September 7, 2007 Share Posted September 7, 2007 <?php $filename = $rows[3]; echo filesize($filename) . ' bytes'; ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 7, 2007 Share Posted September 7, 2007 You surrounded your variable in single quotes. Change it to this: <?php $filename = $rows[3]; echo filesize($filename) . ' bytes'; ?> I'm not sure if filesize() will give you the size of an image...at least from what I'm reading from my google search. Maybe $HTTP_POST_FILES['file name']['size'] Quote Link to comment Share on other sites More sharing options...
djfox Posted September 7, 2007 Author Share Posted September 7, 2007 Ah ok, excellent! One last question, is there anyway to modify this? Like if I want this to display the information in kilobytes or megabytes? Quote Link to comment Share on other sites More sharing options...
trq Posted September 7, 2007 Share Posted September 7, 2007 <?php function filesize_format($bytes, $format = '', $force = '') { $force = strtoupper($force); $defaultFormat = '%01d %s'; if (strlen($format) == 0) { $format = $defaultFormat; } $bytes = max(0, (int) $bytes); $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); $power = array_search($force, $units); if ($power === false) { $power = $bytes > 0 ? floor(log($bytes, 1024)) : 0; } return sprintf($format, $bytes / pow(1024, $power), $units[$power]); } $filename = $rows[3]; echo filesize_format(filesize($filename)); ?> Quote Link to comment Share on other sites More sharing options...
djfox Posted September 7, 2007 Author Share Posted September 7, 2007 Thanks muchly for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.