Steve
Steve

Reputation: 1046

Laravel 5.1 Max image size

I'm using Laravel 5.1 and php 7. I try to implement an image upload. Large images fails to upload. (A white screen appears with no error message) I tested it locally on xampp and on a webspace. With small images it works. It fails with an image of 2.5MB but the max value is 5000.

My controller:

public function fileUpload(Request $request)

{

      if($request->hasfile('filename'))
    {
        foreach($request->file('filename') as $image)
        {

            $targetFolder = public_path().'/images/';

            $name=$image->getClientOriginalName();
            $extension = $image->getClientOriginalExtension(); // add

            $picture = sha1($name . time()) . '.' . $extension; //add

            $image->move($targetFolder, $picture);

            $image = \Intervention\Image\Facades\Image::make(sprintf('images/%s', $picture))->resize(640, null, function ($constraint) {
                $constraint->aspectRatio();
            });
            $image->sharpen(10);
            $image->save();

            $form= new Image();
            $form->filename = $picture;
            $form->appartement_id = $appartement->id;
            $form->save();
        }
    }

    return back()->with('success', 'Your images has been successfully');

}

The questions:

  1. Why there is no error message? Only a white screen appears when it fails to upload. (Maybe there is a necessary configuration to do in one of the laravel config files?
  2. Why it works with smaller images? Where in xampp and on the webspace it's a configuration necessary?

According to my phpinfo file, I have the following values defined: (Local on xampp)

post_max_size = 8M
upload_max_filesize = 10M

On my webspace each is 200M. This values should be high enough?

Upvotes: 0

Views: 914

Answers (3)

Dhruv Raval
Dhruv Raval

Reputation: 1583

First you have to increase values in php.ini as per your recommendation, for example:

upload_max_filesize = 24M 
post_max_size = 32M

In laravel validation files, size corresponds to the file size in kilobytes. check link

try in controller

return redirect()->back()->with('success', ['your message,here']);   

Upvotes: 0

Thursday42
Thursday42

Reputation: 197

Since it works with smaller files, I'm guessing this is related to your PHP configuration and not your code. You should make sure both of these settings in php.ini are large enough (you can change the values to meet your needs).

post_max_size = 512M
upload_max_filesize = 512M

You can run the phpinfo() function to confirm the current settings for your server and make sure your changes have been successful.

Upvotes: 1

Serhii Topolnytskyi
Serhii Topolnytskyi

Reputation: 820

Could you please check server configuration?

PHP - Change the maximum upload file size
NGINX - How to edit nginx.conf to increase file size upload

Upvotes: 0

Related Questions