File Upload Example In Laravel 11

  Mar 2024
  Category: Laravel
File Upload Example In Laravel 11

Welcome To ITSolutionsGuides,

In this Laravel 11 file upload example, we'll explore how to seamlessly handle file uploads within your Laravel 11 application. In Laravel 11, file uploads is crucial for modern web applications where user will upload the file through the input field. When the file is uploaded initialy we should validate the file uploaded and then we should move the uploaded file to new directory and then save the path of the directory with the file name in the database

Let's Create Project & Controller

Lets create the new laravel project using the command,
laravel new file_upload

After creating the project lets create the controller for the image upload using the following artisan command, for detailed explanation about creating the controller

php artisan make:controller FileController


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\View\View;
use App\Models\Document;
use Illuminate\Http\RedirectResponse;
class FileController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index(): View
        return view('fileUpload');
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function store(Request $request): RedirectResponse
            'file' => 'required|mimes:pdf,xlx,csv|max:2048',
        $fileName = time().'.'.$request->file->extension();  
        $request->file->move(public_path('uploads'), $fileName);
        Document::create(['filename' => $fileName ]);
        return back()->with('success', 'File uploaded successfully!')
                     ->with('file', $fileName);

Let's Create Routes


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FileController;
Route::get('file-upload', [FileController::class, 'index']);
Route::post('file-upload', [FileController::class, 'store'])->name('');

Let's Create Blade Files

Lets create the blade file , create website using artisan command


<!DOCTYPE html>
    <title>File Upload Example In Laravel 11 - ITSolutionsGuides</title>
    <link href="" rel="stylesheet" crossorigin="anonymous">
    <link rel="stylesheet" href="" />
<div class="container">
    <div class="card mt-5">
        <h3 class="card-header p-3"><i class="fa fa-star"></i> File Upload Example In Laravel 11 - ITSolutionsGuides</h3>
        <div class="card-body">
                <div class="alert alert-success" role="alert"> 
                    {{ $value }}
            <form action="{{ route('') }}" method="POST" enctype="multipart/form-data">
                <div class="mb-3">
                    <label class="form-label" for="inputFile">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"><i class="fa fa-save"></i> Upload</button>

Let's Run The Project

Lets run the laravel project using the following artisan command,

php artisan serve

enter the below url in the browser,


We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.

Subscribe for NewsLetter

Be the first to know about releases and tutorial news and solutions.

We care about your data in our privacy policy.


ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.

Contact US

ITSolutionsGuides, provide users with an easy-to-use form to reach out for support or inquiries.

whatsapp  gmail  instagram-new--v1  facebook-circled  twitter-circled  linkedin  github  pinterest 

Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides