Laravel 中的干预未上传大图像

Fel*_*ime 1 php laravel intervention

在我的 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');
        }

   }
}
Run Code Online (Sandbox Code Playgroud)

上传 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 致命错误:允许的内存大小为 134217728 字节(试图以 C 为单位分配 20480 字节) :\xampp\htdocs\series\commend-me\CommendMe\vendor\intervention\image\src\Intervention\Image\Gd\Decoder.php 第 119 行,引用:http://localhost/submit

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

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

Mat*_*tey 5

图像操作往往会消耗大量内存,因为图像处理库通常将所有像素“解包”到内存中。因此,一个 3MB 的 JPEG 文件在内存中很容易增长到 60MB,这时您可能已经达到了为 PHP 分配的内存限制。

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

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

memory_limit = 512MB
Run Code Online (Sandbox Code Playgroud)