在laravel中上传时出现最大文件大小(较大文件)错误

时间:2018-11-01 17:33:47

标签: laravel

这是我的代码

public function store(Request $request)
    {
      $this->validate($request,[

            'name'=>'required',

            'file'=>'required|max:3000|mimes:doc,docx,jpeg,png,jpg,pdf,ppt,pptx',

            'Subject'=>'required',


        ]);
       if($request->hasFile('file'))
        {
            //return $request->image->getClientOriginalName();
            $fileName = $request->file->store('public');
            $filesize = $request->file('file')->getClientSize();
        }

        $file=new file;
        $file->name =$request->name;
        $file->file =$fileName;
        $file->Subject =$request->Subject;
        $file->size=$filesize;

        $file->save();
        return redirect(route('file.index'));
    }

但是当我运行代码时,会出现此错误

public function handle($request, Closure $next)
    {
        $max = $this->getPostMaxSize();

        if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) {
            throw new PostTooLargeException;
        }

        return $next($request);
    }

此错误与此代码(PostToLargeException)较大的文件一起出现

我该如何解决大文件的错误,我的文件大小是15MB .ppt格式,但是当我上传小尺寸文件时,我要上传最大100Mb的文件大小 max:10000是什么意思? 预先感谢

1 个答案:

答案 0 :(得分:0)

该方法getPostMaxSize()正在检查post_max_size的配置。您需要将其在php.ini文件中更新为所需的数量。还要检查upload_max_filesize

http://php.net/manual/en/ini.core.php#ini.post-max-size

http://php.net/manual/en/ini.core.php#ini.upload-max-filesize

例如

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 110M

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M

您可以通过在空白页面上运行phpinfo()来检查php.ini的位置。如果您使用的是Apache,则必须在进行修改后重新启动它:

sudo service apache2 restart