Laravel upload file with original file name

Created at 02-Oct-2021 , By samar

Laravel upload file with original file name

Through the use of the programming language, we will work together to solve the "Laravel upload file with original file name" puzzle in this lesson.

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.
  • 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.