search
php

Fix: Upload_max_filesize exceeded error PHP fix

Quick fix for 'Upload_max_filesize exceeded' error in PHP. Learn how to increase file upload limits for your PHP applications.

person By Gautam Sharma
calendar_today January 8, 2026
schedule 2 min read
PHP File Upload Configuration Error Fix Upload Limits

The ‘Upload_max_filesize exceeded’ error occurs when users try to upload files larger than the maximum allowed size configured in PHP settings.


How the Error Happens

❌ Error Scenario:

// ❌ File upload fails if file exceeds upload_max_filesize
if ($_FILES['upload']['error'] === UPLOAD_ERR_INI_SIZE) {
    // Error: File exceeds upload_max_filesize directive in php.ini
}

✅ Quick Fix - Increase Upload Limits

Solution 1: Update php.ini

; ✅ Increase upload limits in php.ini
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
memory_limit = 256M

Solution 2: Update .htaccess

# ✅ Increase upload limits in .htaccess
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value memory_limit 256M

Solution 3: Check Upload in PHP

<?php
// ✅ Verify upload size before processing
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($_FILES['upload']['error'] === UPLOAD_ERR_INI_SIZE) {
        die('File too large. Maximum size: ' . ini_get('upload_max_filesize'));
    }
    
    // ✅ Process upload
    $file = $_FILES['upload'];
    move_uploaded_file($file['tmp_name'], 'uploads/' . $file['name']);
}
?>

Solution 4: Display Current Limits

<?php
// ✅ Check current upload limits
echo 'Max upload size: ' . ini_get('upload_max_filesize') . '<br>';
echo 'Max post size: ' . ini_get('post_max_size') . '<br>';
echo 'Max execution time: ' . ini_get('max_execution_time') . '<br>';
?>
Gautam Sharma

About Gautam Sharma

Full-stack developer and tech blogger sharing coding tutorials and best practices

Related Articles

php

Fix: PHP mail() not working error

Quick fix for PHP mail() not working error. Learn how to configure PHP mail settings and use alternatives like SMTP for reliable email delivery.

January 8, 2026
php

Fix: Session_start(): Cannot start session error

Quick fix for 'Session_start(): Cannot start session' error in PHP. Learn how to properly configure and manage PHP sessions.

January 8, 2026
php

Fix: Undefined constant error PHP fix

Quick fix for 'Undefined constant' error in PHP. Learn how to properly define and use constants in PHP applications.

January 8, 2026