0

i am trying to upload video on my laravel project it didn't uploading but when i am trying to upload images it will works perfectly

    {
        $request->validate([
            'file' => 'required',
        ]);
       $fileName = time();

       $request->file->move(public_path('videos'), $fileName);
       $fileupload = new FileUpload;
        $fileupload->filename=$fileName;
        $fileupload->save();

        return response()->json(['success'=>'File Uploaded Successfully']);
    }
Ram Sharma
  • 60
  • 1
  • 8

1 Answers1

0

Well I would store the file first so that the code would rather looks like:

public function uploadVideo(Request $request) {
    $request->validate([
        'file' => 'required',
    ]);
    $filename = time();

    /* Storing the file on the disk  */
    $request->file->storeAs('videos', $filename);

    /* Recording the upload on the database */
    $fileupload = new FileUpload;
    $fileupload->filename = $filename;
    $fileupload->save();

    return response()->json(['success'=>'File Uploaded Successfully']);
}

Indeed, in your code, your are moving a file that isn't stored... It can't work fine.

I would suggests you to read more the documentation about File Storage as you would have to use a command to make a symlink :

php artisan storage:link
Alexandre Gérault
  • 323
  • 1
  • 2
  • 13