Amir Hossein
Amir Hossein

Reputation: 1144

My problem never Solved, Cannot upload file greater than 2M in laravel framework

I use laravel framework v5.8 for my project and I need to upload video When the upload is complate it gives me Illuminate\Http\Exceptions\PostTooLargeException and when I disable this:

if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) {
     throw new PostTooLargeException;
}

code in validatePostSize.php it gives me this:

error Warning: POST Content-Length of 16195196 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

and no file uploaded

php.ini settings:

upload_max_filesize=2000M
max_file_uploads=2000M
memory_limit=128M
post_max_size=800M

and I checked them in xampp phoInfo()

how can I resolved this.

htaccess code:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    php_value post_max_size=200M
    php_value upload_max_filesize=200M
</IfModule>

Upvotes: 2

Views: 904

Answers (2)

Amir Hossein
Amir Hossein

Reputation: 1144

I solved this problem by creating php.ini file inside the public directory and restarted my apache and rerun PHP artisan serve command

new php.ini code:

[PHP]
upload_max_filesize=2000M
max_file_uploads=2000M
memory_limit=128M
post_max_size=800M

Upvotes: 2

Udhav Sarvaiya
Udhav Sarvaiya

Reputation: 10071

This error message is an indication of that the file you are trying to upload is larger than your web host allows (default file upload size is 2 MB)

A solution is simple, need to increase the file size upload limit.

First of all, stop the XAMPP/Wamp then go to xampp\php\php.ini file, Find these lines in the php.ini file and replace it following numbers

upload_max_filesize = 64M

Save the changes, And then restart your XAMPP/Wamp, Also, refresh your website and try uploading the file again. You will now get success.

Upvotes: 0

Related Questions