5

What is the proper way to detect that post_max_size was exceded in php? It looks like I can only check for an empty $_POST array, which seems imprecise. I need to detect if a file that was uploaded was to big and produce a proper error message.

McLeopold
  • 5,967
  • 5
  • 21
  • 14
  • The `$_FILES` array [will contain an error message](http://www.php.net/manual/en/features.file-upload.errors.php) if the maximum *file* size is exceeded. Not sure what happens if `post_max_size` breaks – Pekka Jun 07 '11 at 14:26
  • 1
    @Pekka웃 - Both `$_FILES` and `$_POST` [become empty](http://es1.php.net/manual/en/ini.core.php#ini.post-max-size). – Álvaro González Jan 20 '14 at 10:44

2 Answers2

2

You can't, if the value of post_max_size is exceeded, super globals will be empty.

A solution is to add in your form a $_GET variable

<form action="check.php?shouldHaveFilesInHere">

and to check if other super globals are filled or not in check.php.

http://www.php.net/manual/en/ini.core.php#ini.post-max-size

Gérald Croës
  • 3,799
  • 2
  • 18
  • 20
0

If you want to know if the file that was uploaded is too large you should use $_FILE['error'].

http://php.net/manual/en/features.file-upload.errors.php

TJHeuvel
  • 12,403
  • 4
  • 37
  • 46
  • 3
    the $_FILES (not $_FILE) array is blank as well, so this doesn't work. – McLeopold Jun 07 '11 at 14:23
  • 1
    No you can't check if the file was to large (due to post_max_size) in $_FILES['error'] as super globals will be empty. It would have worked with upload_max_filesize though. – Gérald Croës Jun 07 '11 at 14:36