简体   繁体   中英

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.

This is the store method on my VideoController (even having max:255 on description throws QueryException anyways)

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

 $request->validate([
        'title' => 'required|unique:videos|max:55',
        'desc' => 'required|max:255',
        'video' => 'required|file|max:85000'
    ]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM