validatepostsize.php,在ValidatePostSize.php第22行laravel中的PostTooLargeException

检查php.ini文件中的以下参数.

我曾多次遇到过这个问题,通常是因为max_file_size默认设置为2M.

> max_file_size

> upload_max_filesize

> post_max_size

**编辑

我被问到如何在将文件发送到PHP之前使用Laravel中的validate方法验证文件大小,并向用户警告大文件.你可以这样做:

1.为屏幕创建错误警报

这就是我的样子.我使用bootstrap 3风格.将这样的内容添加到您的布局中(只有在出现错误时才会显示).

@if (count($errors) > 0)

Whoops! There were some problems with your input.

@foreach ($errors->all() as $error)

{{ $error }}

@endforeach

@endif

2.确定您将在预先确定的验证类中使用的验证器**

转到您的项目/ Resources / lang / en / validators.php您将在laravel中找到所有可用的验证.你会看到他们在那里有这个:

'max' => [

'numeric' => 'The :attribute may not be greater than :max.',

'file' => 'The :attribute may not be greater than :max kilobytes.',

'string' => 'The :attribute may not be greater than :max characters.',

'array' => 'The :attribute may not have more than :max items.',

],

这是我用来检查文件大小的验证规则.

** 4.创建您的请求文件**

php artisan make:request yourRequest

** 5.更新您的请求文件**

转到yourProject / app / Http / Requests / yourRequest.php并在规则方法’file_name’=>中添加以下内容: ‘max:10’更新10到你的限制值,以千字节为单位:

public function rules()

{

return [ 'profile_pic' => 'required|image|mimes:jpg|max:10',

];

}

6.使用请求文件管理规则的任何一方提出请求.

因此,在这种情况下,我们将其命名为yourRequest,因此您的save方法将具有:

public function upload(Requests\yourRequest $request)

还要确保您的Controller使用其中的请求类,如下所示:

use App\Http\Requests;

如果你这样做,你会有一个如下错误:

54f04317f6269fa449299ef242d3e144.png

另一种选择是使用Image类缩小文件(如果是图像).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值