Mark
Mark

Reputation: 5088

File upload returns error even if image size way below upload_max_filesize

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'));
          }
 }

Upvotes: 0

Views: 373

Answers (2)

Tio
Tio

Reputation: 567

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.

Upvotes: 2

Eugen Rieck
Eugen Rieck

Reputation: 65264

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.

Upvotes: 0

Related Questions