简体   繁体   English

当文件上传超过最大上传限制时如何显示错误? - Laravel

[英]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.

相关问题 该文件超过了Laravel中的upload_max_filesize ini指令(限制为2048 KiB) - The file exceeds your upload_max_filesize ini directive (limit is 2048 KiB) in Laravel Laravel 最大验证对文件上传不起作用,我仍然可以上传大于限制的图像。 为什么会这样? - Laravel max validation doesn't take effect on file upload and I can still upload images that are bigger than the limit. Why is this happening? 档案上传上限 - max file upload limit Debian - Symfony 2 - 文件“file”超出了upload_max_filesize ini指令(限制为2048 kb)。 (500内部服务器错误) - Debian - Symfony 2 - The file “file” exceeds your upload_max_filesize ini directive (limit is 2048 kb). (500 Internal Server Error) 如何中止超过php上传上限的文件上传? - How can I abort a file upload that exceeds php's upload maximum? 如何确定PHP中的最大文件上传限制 - How to determine the max file upload limit in php 上传的文件超过了php.ini中的upload_max_filesize指令,但文件小于限制 - The uploaded file exceeds the upload_max_filesize directive in php.ini but the file is smaller than limit 如何在Laravel 4中更新文件上传? - How can I update a file upload in Laravel 4? Laravel - 超过 PHP 最大上传大小限制时验证文件大小 - Laravel - validate file size when PHP max upload size limit is exceeded 尝试通过PHP解析SDK上传文件时,如何限制文件大小? - How can I limit the file size when I try to upload files via PHP parse SDK?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM