How To File Upload In Laravel 10 Example

Websolutionstuff | Mar-15-2023 | Categories : Laravel

In this article, we will see how to file upload in laravel 10 examples. Here, we will learn about the laravel 10 file upload example step by step. Also, we will see how to validate file mime types, size, etc using laravel 10 validation rules.

Also, you can store the file name in the database and display a preview of them. But, here we will simply store the file in the public folder. So, we need to create routes and controllers for that.

So, let's see the laravel 10 file upload example, file upload in laravel 10, how to upload files in laravel 10, and laravel 10 upload files to storage.

Step 1: Install Laravel 10

In this step, we will install laravel 10 using the following code. So, run the following command to the terminal.

composer create-project laravel/laravel laravel_10_file_upload_example


Step 2: Add Routes

Now, we will route it into the web.php file.


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FileUploadController;

Route::get('file-upload', [FileUploadController::class, 'index']);
Route::post('file-upload', [FileUploadController::class, 'store'])->name('');



Step 3: Create FileUploadController

In this step, we will create a FileUploadController file. So, add the following code to that file.


namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FileUploadController extends Controller
    public function index()
        return view('fileUpload');

    public function store(Request $request)
            'file' => 'required|mimes:pdf,xlx,csv|max:1024',
        $fileName = time().'.'.$request->file->extension();  
        $request->file->move(public_path('uploads'), $fileName);
        return back()
            ->with('success','File Uploaded successfully.')
            ->with('file', $fileName);



Store File in Public Folder:

$request->file->storeAs('uploads', $fileName); 

// storage/app/uploads/filename.jpg

Store File in S3:

$request->file->storeAs('uploads', $fileName, 's3');

Store File in Storage Folder:

$request->file->move(public_path('uploads'), $fileName);

// public/uploads/filename.jpg


Step 4: Create Blade File

In this step, we will create a fileUpload.blade.php file.


<!DOCTYPE html>
    <title>How To File Upload In Laravel 10 Example -</title>
    <link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
    <div class="panel panel-primary">
        <div class="panel-heading text-center mt-5">
            <h2>How To File Upload In Laravel 10 Example -</h2>
        <div class="panel-body mt-5">
            @if ($message = Session::get('success'))
                <div class="alert alert-success alert-dismissible fade show mb-2 mt-4" role="alert">
                    {{ $message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            <form action="{{ route('') }}" method="POST" enctype="multipart/form-data">
                <div class="mb-3">
                    <label class="form-label" for="inputFile">Select File:</label>
                        class="form-control @error('file') is-invalid @enderror">
                        <span class="text-danger">{{ $message }}</span>
                <div class="mb-3">
                    <button type="submit" class="btn btn-success">Upload</button>




You might also like:

Recommended Post
Featured Post
Carbon Add Years To Date In Laravel 9
Carbon Add Years To Date In La...

In this article, we will see carbon add years to date in laravel 9. Carbon provides addYear() and addYears() functi...

Read More


How To Reset Modal Form In jQuery
How To Reset Modal Form In jQu...

Have you ever seen those pop-up boxes on websites? They're called modal forms, and they make it easier to do things...

Read More


How To Install VueJs In Laravel
How To Install VueJs In Larave...

In this article, we will see how to install vue js in the laravel framework. if you are not aware of you are freshe...

Read More


How To Create AJAX Pagination In Laravel 9
How To Create AJAX Pagination...

In this article, we will see how to create ajax pagination in laravel 9. Here, we will learn how to create jquery a...

Read More