Felix Maxime Felix Maxime - 9 months ago 65
PHP Question

Large images not being uploaded with Intervention in Laravel

In my laravel setup, I'm currently using Intervention for image uploads.

However, at the moment, images above the size of 3MB are not being uploaded.

give me back 5MB and 8MB respectively.

My image save controller is as follows:

public function saveImage(Request $request) {
if (Auth::check()) {
$this->validate($request, [
'title' => 'required|max:50|min:2|alpha_num',
'mature' => 'required',
'categorie' => 'required',
'description' => 'string|max:2000',
'fileUpload' => 'required',

$galleryConfirmation = Gallery::where('id', $request->get('gallerySelect'))->value('created_by');

if (Auth::user()->id == $galleryConfirmation || $galleryConfirmation == 0 || $galleryConfirmation == null ) {

$file = $request->file('fileUpload');

if ($file->getClientSize() > 3999999) {

$filename = time() . '.' . $file->getClientOriginalExtension() ;

Image::make($file)->save( public_path('/uploads/artistUploads/' . $filename ) );

$thumb = Image::make($file);
$thumb->resize(null, 200, function ($constraint) {
$thumb->save( public_path('/uploads/artistUploads/thumbs/' . $filename , 60) );

$images = new Images;

$images->title = $request->input('title');
$images->file_name = $filename;
$images->file_size = $file->getClientSize();
$images->file_mime = $file->getClientMimeType();
$images->file_path = 'uploads/artistUploads/' . $filename;
$images->description = $request->input('description');
$images->mature = $request->input('mature');
$images->categorie = $request->get('categorie');
if (Auth::user()->id == $galleryConfirmation) {
$images->gallery_id = $request->get('gallerySelect');
$images->created_by = Auth::user()->id;


return redirect()->back()->with('info', 'Image successfully uploaded.');


if (!Auth::user()->id == $galleryConfirmation) {
return redirect()->back()->with('info', 'Something went wrong');


When uploading a file of 3MB or higher, I get back only a white page. Furthermore, my
file is not showing any errors.

By using
after each line, I was able to find out that the crash happens at this line:

Image::make($file)->save( public_path('/uploads/artistUploads/' .
$filename ) );



There was an error in the apache error log:

[Mon Oct 31 04:17:31.109685 2016] [:error] [pid 13024:tid 1596] [client ::1:55986] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in C:\xampp\htdocs\series\commend-me\CommendMe\vendor\intervention\image\src\Intervention\Image\Gd\Decoder.php on line 119, referer: http://localhost/submit

This error shows up when trying to upload a picture above 3MB.

I raised the memory limit in my php.ini file, however I still find this rather strange. Why is this taking up so much memory? Is this normal?

Answer Source

Image operations tend to be quite memory exhausting because image handling libraries usually 'unpack' all the pixels to memory. A JPEG file of 3MB can thus easily grow to 60MB in memory and that's when you've probably hit the memory limit allocated for PHP.

As far I remember, XAMP only allocates 128 MB RAM for PHP.

Check your php.ini and increase the memory limit, e.g.:

memory_limit = 512MB