[英]How can I show error when file upload exceeds max upload limit? - Laravel
Hii Im making project for school, and its a site where users can upload videos, I set the max upload file to 85MB on php.ini, the problem is that if I upload files larger than this then QueryException is thrown, same happens if I fill a description too large or a name too large.我正在为学校制作项目,它是一个用户可以上传视频的网站,我在 php.ini 上将最大上传文件设置为 85MB,问题是如果我上传的文件大于这个,则会抛出 QueryException,如果我填写过大的描述或过大的名称。
This is the store method on my VideoController (even having max:255 on description throws QueryException anyways)这是我的 VideoController 上的存储方法(即使描述中有 max:255 也会抛出 QueryException)
public function store(Request $request)
{
$request->validate([
'title'=>'required|unique:videos|max:55',
'desc'=>'required|max:255',
'video'=>'required',
]);
$pathV=$request->file('video')->store('videos','public');
$user = Auth::user()->id;
Video::create(['title'=>$request->title,
'cont'=>$pathV,
'desc'=>$request->desc,
'user'=>$user
]);
$videos=Video::all();
return view('videos.all',compact('videos'));
}
Add this validation rule to the validation array - file|max:85000
将此验证规则添加到验证数组 -
file|max:85000
$request->validate([
'title' => 'required|unique:videos|max:55',
'desc' => 'required|max:255',
'video' => 'required|file|max:85000'
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.