Laravel 中的干预未上传大图像

Large images not being uploaded with Intervention in Laravel

在我的 laravel 设置中,我目前正在使用 Intervention 进行图片上传。

但是,目前无法上传 3MB 以上的图片。

ini_get('upload_max_filesize')ini_get('post_max_size') 分别还给我 5MB 和 8MB。

我的图片保存控制器如下:

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) {
                dd("nooooo");
            }

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

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

            $thumb = Image::make($file);
            $thumb->resize(null, 200, function ($constraint) {
                $constraint->aspectRatio();
            });
            $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;

            $images->save();

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

        }

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

   }
}

上传 3MB 或更大的文件时,我只返回一个白页。此外,我的 laravel.log 文件没有显示任何错误。

通过在每一行之后使用 dd('test');,我发现崩溃发生在这一行:

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

帮忙?

编辑:

apache 错误日志中有一个错误:

[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

尝试上传超过 3MB 的图片时出现此错误。

我在 php.ini 文件中提高了内存限制,但我仍然觉得这很奇怪。为什么这会占用这么多内存?这正常吗?

图像操作往往非常耗费内存,因为图像处理库通常 'unpack' 所有像素都存储在内存中。因此,一个 3MB 的 JPEG 文件在内存中很容易增长到 60MB,这时您可能已经达到为 PHP.

分配的内存限制

据我所知,XAMP 只为 PHP 分配了 128 MB RAM。

检查您的 php.ini 并增加内存限制,例如:

memory_limit = 512MB