0

I set a limit with a max of 10MB to uploads in my php code with

define ('MAX_FILE_SIZE', 1048576 * 10);
if ($_FILES['uploadphoto']['size'] > MAX_FILE_SIZE) { $errors[] = "Photo exceeds 10MB limit.";}

Which works fine. But I know you can put this;

<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />

In the form so that the user knows he uploaded a file too large instantly. This works but it doesn't give the user an error message that the file was too large. What can I do to show an error message?

user2127833
  • 179
  • 2
  • 5
  • 16
  • 1
    Have you tried JavaScript? – user2019515 Jun 15 '13 at 02:28
  • @user2019515 I thought of using it but I don't know enough of it to use for this. Can you think of a solution using it? – user2127833 Jun 15 '13 at 02:35
  • See: https://www.google.com/#sclient=psy&fp=540b244135372103&q=javascript%20form%20validation&bav=on.2,or.r_cp.r_qf.&cad=b and http://stackoverflow.com/questions/7497404/find-out-file-size-before-uploading-using-jquery-ajax – user2019515 Jun 15 '13 at 02:37
  • 1
    If you specified `MAX_FILE_SIZE` on client side and client break that size, it would reflect in [`$_FILES["uploadphoto"]["error"]`](http://www.php.net/manual/en/features.file-upload.errors.php). – Passerby Jun 15 '13 at 03:30

1 Answers1

0

Forgot about case 2!

switch($_FILES['uploadphoto']['error']) {

case 2:
echo 'Photo exceeds 10MB limit.';
break;
}

Thank you @Passerby!

user2127833
  • 179
  • 2
  • 5
  • 16