0

I am trying to get the file size of an image. If I upload below a 5 MB size image, then this function is properly calculating image size. But if the image file size is exceeded then it is not calculating image file !

$size = filesize($_FILES['file']['tmp_name']);

I am not understanding what the problem is.

Sandeep Kamble
  • 159
  • 1
  • 1
  • 9
  • 2
    Check to see that your file_exists() first, incase it has not uploaded correctly – bumperbox Oct 05 '12 at 05:53
  • 3
    If uploadsize is exceeded, the file isn't physically available on the server. – Arkadiusz 'flies' Rzadkowolski Oct 05 '12 at 05:53
  • Maximum size limits aside (which are probably what you're running into), the `$_FILES` array already contains the file size in the `'size'` entry; there's no need to call `filesize` yourself. – John Flatness Oct 05 '12 at 06:07
  • I'm guessing the file exceeds your upload limit defined in `php.ini` and you aren't checking the `error` element of the `$_FILES['file']['error']` to see if it failed before trying to get the size. – MrCode Oct 05 '12 at 06:16

1 Answers1

0

untested code

 if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
        $postMax = ini_get('post_max_size'); //grab the size limits...
        echo "<p style=\"color: #F00;\">\nPlease note files larger than {$postMax} will result in this error!<br>Please be advised this is not a limitation in the CMS, This is a limitation of the hosting server.
        callMyForm(); //bounce back to the just filled out form.
}
elseif(// continue on with processing of the page...
mymotherland
  • 7,968
  • 14
  • 65
  • 122
  • 1
    found some post....check this http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size – mymotherland Oct 05 '12 at 05:59