Jump to content

[SOLVED] A little hep with getimagesize() ?


djfox

Recommended Posts

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

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']

<?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));

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.