Reputation: 1046
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:
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
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
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
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