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) Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/ Share on other sites More sharing options...
trq Posted September 7, 2007 Share Posted September 7, 2007 filesize(). Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343461 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. Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343470 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'; ?> Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343472 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'] Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343475 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? Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343476 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)); ?> Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343478 Share on other sites More sharing options...
djfox Posted September 7, 2007 Author Share Posted September 7, 2007 Thanks muchly for the help! Link to comment https://forums.phpfreaks.com/topic/68308-solved-a-little-hep-with-getimagesize/#findComment-343479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.