icelander's avatar

how to upload a video file into my database in laravel

hi. please how do I upload a video or powerpoint or image to my table in my database. but after what I have done I got this error message

The slide must be a file of type: mp4, ppx, pdf, ogv, jpg, webm. 
 public function doupload(Request $request){

    	$this->validate($request,[
            'subject'=> 'required',
            'class'=> 'required',
            'topic'=> 'required',
            'slide'=> 'required|mimes:mp4,ppx,pdf,ogv,jpg,webm|max:1999',
             

        ]);

       $name= Auth::guard('teacher')->user()->name;
       return $name;
        if($request->hasFile('slide')){
            $filenameWithExt= $request->file('slide')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            $extension = $request->file('slide')->getClientOriginalExtension();
            $fileNameToStore = $filename. '_'.time().'.'.$extension;
            $path = $request->file('slide')->storeAs('public/videos/',$fileNameToStore);
        }else{
            $fileNameToStore = 'noimage.jpg';
        }
         $slide = new Slide;
        $slide->topic = $request->input('topic');
         $slide->subject = $request->input('subject');
         $slide->class = $request->input('class');
         $slidefile = $fileNameToStore;
         $slide->teacher = $request->input('teacher');
         $slide->save();

        return back()->with('success', ' Upload Successfull');
    }
0 likes
8 replies
MichalOravec's avatar

You have to add all you allowed files

slide'=> 'required|mimes:mp4,ppx, ppt, pptx,pdf,ogv,jpg,webm|max:1999',

I think for powerpoint is ppt and pptx.

icelander's avatar

I added a jpg file but it still gave me back that error

The slide must be a file of type: mp4, ppx, pdf, ogv, jpg, webm.
icelander's avatar

I tried uploading a jpg file but it still gave me the same error.

Armani's avatar

Can you show me your blade file, the form section, because you may forgot to add

<form enctype="multipart/form-data">
icelander's avatar

this is my form

  <form role="form" method="post" enctype="multipart/form-data" action=" {{route('teacher.upload')}}">
MichalOravec's avatar

@icelander Add also jpeg to your validation

slide'=> 'required|mimes:mp4,ppx,ppt,pptx,pdf,ogv,jpeg,jpg,webm|max:1999',
Armani's avatar

Try this syntax:

'video' => 'mimetypes:video/avi,video/mpeg,video/quicktime'

it is from Laravel documentation:

https://laravel.com/docs/7.x/validation#rule-mimetypes

Please or to participate in this conversation.