Upload Max Filesize Exceeded

PHP Warning: POST Content-Length exceeds the limit / UPLOAD_ERR_INI_SIZE

Quick Answer

The uploaded file exceeds the size limit configured in php.ini. Increase upload_max_filesize and post_max_size, or validate file size on the client side before uploading.

Why This Happens

PHP limits file uploads through two ini settings: upload_max_filesize controls individual file size and post_max_size controls total POST data size. When a file exceeds these limits, the upload silently fails and $_FILES['file']['error'] is set to UPLOAD_ERR_INI_SIZE (1).

The Problem

// php.ini: upload_max_filesize = 2M
$file = $_FILES['upload'];
move_uploaded_file($file['tmp_name'], '/uploads/' . $file['name']);
// Silently fails for files over 2MB

The Fix

$file = $_FILES['upload'];
if ($file['error'] !== UPLOAD_ERR_OK) {
    $errors = [
        UPLOAD_ERR_INI_SIZE => 'File exceeds upload_max_filesize',
        UPLOAD_ERR_FORM_SIZE => 'File exceeds MAX_FILE_SIZE',
        UPLOAD_ERR_PARTIAL => 'File was only partially uploaded',
        UPLOAD_ERR_NO_FILE => 'No file was uploaded',
    ];
    throw new RuntimeException($errors[$file['error']] ?? 'Upload error');
}
move_uploaded_file($file['tmp_name'], '/uploads/' . basename($file['name']));

Step-by-Step Fix

  1. 1

    Check error code

    Always check $_FILES['file']['error'] before processing. UPLOAD_ERR_OK (0) means success; any other value is an error.

  2. 2

    Increase limits if needed

    Set upload_max_filesize and post_max_size in php.ini. post_max_size must be larger than upload_max_filesize.

  3. 3

    Add client-side validation

    Validate file size with JavaScript before upload to give users immediate feedback without waiting for the upload to complete.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free