How to upload video using file button?

I,ve been trying to upload a video via the file button but i'm not sure how to save the file to the public folder.

This is my code in the controller:

    if($request->hasFile('videofile')){

        $video=$request->file('videofile');
        $filename=time() . '.' . $video->getClientOriginalExtension();
        $filenamesave=File::save(public_path('videos/'.$filename));
    }

    $link=new videos();
    $link->user_id=auth()->user()->id;
    $link->video=$filename;
    $link->save(); 

I'm getting this error:

Method save() doesn't exist

2 answers

  • answered 2018-07-11 03:06 Jay Are

    Unfortunately, File::save() does not exists, instead use put(). You check the documentation, https://laravel.com/docs/5.6/filesystem#obtaining-disk-instances

  • answered 2018-07-11 04:21 Mahmudul Hasan

    First Receive Video File

    $video = $request->file('videofile');
    

    Create Folders "/uploads/video/" inside your public folder.

      if($request->hasFile('videofile')){
            $video = $request->file('video');
            $video_name =date("j-M-Y").'.'.time().$video->getClientOriginalExtension();
            $destinationPath = public_path('/uploads/video/');
            $video->move($destinationPath, $video_name);
            $save_path =  '/uploads/video/';
            $filename = $save_path.$video_name; 
        } 
    

    Save your new link to database.

    $link=new videos();
    $link->user_id=auth()->user()->id;
    $link->video=$filename;
    $link->save();
    

    And Use this link with asset() method. like, asset($data->video).