Laravel upload file with original file name

Sometimes you have to upload the file in directory with the same (original) file name in Laravel. In that case you can get the file name of file with getClientOriginalName() and upload in directory.

Answers 1
  • Upload file in directory with its original file name in laravel

    $file = $request->file('avatar');
    $fileName = $file->getClientOriginalName()
    $file->storeAs('avatars', $fileName);

    This code snippet will upload the file with its original filename to directory. You can get the input file using $request->file('filename') with the file name attribute and upload the image with their original filename. 

  • Back to code snippet queries related laravel