Search code examples
phplaravel

Laravel Files upload


I'm encountering the following error when attempting to upload an image in my Laravel project:

Error: Illuminate\Http\Exceptions\PostTooLargeException

I understand that this issue is related to file size limitations. Based on my research, I modified the following settings in my php.ini file:

post_max_size=1g
upload_max_filesize=1g
max_execution_time=3000
max_input_time=3000

After making these changes, I restarted Apache, but the error persists.

What I Have Tried

  • Updated php.ini settings (as shown above)
  • Restarted Apache and MySQL to apply changes
  • Checked Laravel configuration to ensure proper file storage settings
  • Verified that the correct php.ini file is being modified using

Solution

  • The above usually occur due maximum upload size limit in php, you can try below step to fix it.

    Increase PHP Upload Limits Update the following values in your php.ini file:

    upload_max_filesize = 100M
    post_max_size = 100M
    max_execution_time = 300
    max_input_time = 300
    

    Update Apache Configuration (If Using Apache) In your .htaccess or apache2.conf:

    php_value upload_max_filesize 100M
    php_value post_max_size 100M
    

    Check File Validation in Laravel

    $request->validate([
        'file' => 'required|file|max:102400', // 100MB
    ]);
    

    Just give a try, if the above help