0

When I try to upload an image over about 4mb, then $_FILES['upload']['error'] returns 1 and the file wont upload. But in my php.ini I have upload_max_filesize set to 20mb....

Why am i getting an error?

Heres php code to check for error

if ($_FILES['upload']['error']) {
   array_push($not_uploaded, $_FILES['upload']['name']);
   if ($_FILES['upload']['error'] == 1) {
     trigger_error('Iimage exceeded server php upload limit', E_USER_WARNING);
     array_push($error_msgs, elgg_echo('services:image_mem'));
   } else {
     array_push($error_msgs, elgg_echo('services:unk_error'));
          }
 }
11
  • phpinfo(), make suer its the right php.ini file; most systems would have 2 at least (cli, and via Apache) Commented May 23, 2012 at 23:38
  • Could you please post your php code, thanks! Commented May 23, 2012 at 23:39
  • Several other places could be setting that .. a phpinfo(); will tell you what the settings it's using actually are, and where they are being gotten from. Commented May 23, 2012 at 23:40
  • Do you have the MAX_FILE_SIZE hidden field in the correct place? Commented May 23, 2012 at 23:47
  • I just found that upload_max_filesize is also set in .htaccess and its set to 5242880. This is probably the value used (phpinfo() says upload_max_filesize is 20m). But still, the files im trying to upload are 4.5 and 4.7mb but an error of 1 is still being returned.. Commented May 24, 2012 at 0:02

2 Answers 2

2

You should also check the configuration of the variable post_max_size in the php.ini file.

In PHP docs: Common Pitfalls

If post_max_size is set too small, large files cannot be uploaded. Make sure you set post_max_size large enough.

Sign up to request clarification or add additional context in comments.

Comments

0

As the php docs say, you need to send a (most often hidden) field with the name MAX_FILE_SIZE before the actual file. While theoretically even 4MB shouldn't work without it, this might be some hardcoded default.

Use the example form of the mentioned PHP docs page as a starting point.

4 Comments

oh I didnt know about MAX_FILE_SIZE, i thought i had to always check file size after its up loaded. This is useful:)
Actually MAX_FILE_SIZE is only an indication, and most browser's just ignore it, you always have to upload the file to check it's size in PHP.
@Tio MAX_FILE_SIZE is not only for the Browser, it is also sent as a POST variable, and parsed by PHP. This doesn't mean, you can use it to bypass the limits in php.ini
@EugenRieck, yes, your right, I forgot to mention that the MAX_FILE_SIZE is sent by POST

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.