检查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;
如果你这样做,你会有一个如下错误:
另一种选择是使用Image类缩小文件(如果是图像).