上传文件时,laravel显示PostTooLargeException是什么解决方案来处理这个问题
检查php.ini
文件中的以下参数。您的文件的大小必须大于php.ini
文件中为这些参数设置的大小。
您需要对php.ini
文件进行更改。
只需将max_file_size
,upload_max_filesize
和post_max_size
设置为更高的值40M
或您想要的更多值。
使用以下变量更新php.ini
文件:
max_file_size
upload_max_filesize
post_max_size
对于临时基础,您可以通过访问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
或者我们可以使用客户端验证来检查大小并验证大小希望这会有所帮助。