上传文件时,laravel显示PostTooLargeException是什么解决方案来处理这个问题

问题描述 投票:0回答:4

上传文件时,laravel显示PostTooLargeException是什么解决方案来处理这个问题

laravel laravel-5.6
4个回答
0
投票

检查php.ini文件中的以下参数。您的文件的大小必须大于php.ini文件中为这些参数设置的大小。

  • MAX_FILE_SIZE
  • 的upload_max_filesize
  • 的post_max_size

0
投票

您需要对php.ini文件进行更改。

只需将max_file_sizeupload_max_filesizepost_max_size设置为更高的值40M或您想要的更多值。


0
投票

使用以下变量更新php.ini文件:

max_file_size
upload_max_filesize
post_max_size

0
投票

对于临时基础,您可以通过访问ValidatePostSize.php来禁用此检查

public function handle($request, Closure $next)
{
 //       if ($request->server('CONTENT_LENGTH') > $this->getPostMaxSize()) 
             {
                 //            throw new PostTooLargeException;
   //        }

    return $next($request);
}

或者您可以在App \ Exceptions \ handler中处理异常

public function render($request, Exception $exception)
{
  if ($exception instanceof \Illuminate\Http\Exceptions\PostTooLargeException) {
     // handle response accordingly
   }
   return parent::render($request, $exception);
}

否则需要更新php.ini文件

upload_max_filesize = 10MB          //size you want

或者我们可以使用客户端验证来检查大小并验证大小希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.