Support the ongoing development of Laravel.io →
Laravel API
1

Hi Kamal

In Laravel, handling file uploads is quite straightforward. Here’s a simple example:

  1. Create a form in your Blade file:

    <form action="{{ route('upload') }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="file"> <button type="submit">Upload</button> </form>
  2. Add a route in web.php:

    Route::post('/upload', [FileController::class, 'store'])->name('upload');

  3. Handle the upload in your controller (FileController):

    public function store(Request $request) { $request->validate([ 'file' => 'required|mimes:jpg,png,pdf|max:2048', ]);

    $path = $request->file('file')->store('uploads', 'public');
    
    return back()->with('success', 'File uploaded successfully!')->with('path', $path);
    

    }

  4. The file will be stored in storage/app/public/uploads, and you can access it via storage_link (php artisan storage:link).

That’s it — Laravel handles most of the work for you. If you need more control (like renaming files, saving paths to the database, etc.), you can easily extend this logic.

Best regards, [Rivael Saputra]

0

Sign in to participate in this thread!

Native PHP

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.