Tech Magazine

Handling Multiple File Upload in Laravel

1 8,900

Get real time updates directly on you device, subscribe now.

In this article, we will discuss “Handling Multiple File Upload in Laravel”. As I already explain the file upload in our previous tutorial “Handling File Upload in Laravel”. Here, I will explain how to upload multiple files.

I’m assuming you are familiar with Laravel. If not then you can start with our Laravel Collection to increase your knowledge.

Follow the step given below, to create an example for upload multiple images.

Install New Laravel Application

You can use the following composer command to install the Laravel application.

composer create-project laravel/laravel laraImg --prefer-dist

Create Routes

Here, we will add two routes in “routes/web.php”.

Route::get('/upload-image', 'UploadController@getUploadForm');
Route::post('/upload-image', 'UploadController@postUploadForm');

“get” route is redirecting a user to upload form. And, “post” route is used to process the uploading.

Create Controller

Using the following Artisan command to create “UploadController”.

php artisan make:controller UploadController

After that, a newly created controller located at “app/Http/Controllers”.


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UploadController extends Controller
     * Upload form
    public function getUploadForm()
        return view('upload-image');

     * Post upload form
    public function postUploadForm(Request $request)
            'upload.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'

        if($request->hasFile('upload')) {

            $imageNameArr = [];
            foreach ($request->upload as $file) {

                // you can also use the original name
                $imageName = time().'-'.$file->getClientOriginalName();
                $imageNameArr[] = $imageName;

                // Upload file to public path in images directory
                $file->move(public_path('images'), $imageName);

                // Database operation


        return back()
            ->with('success','You have successfully upload image.')

Create Blade Template

Creating a blade template “upload-image.blade.php” in the “resources/views” directory, which contains the HTML form.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Laravel 7 - Image Upload Example</title>
    <link href="" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        .wrap {
            padding: 30px 0;
        h2 {
            margin-bottom: 30px;
    <div class="container">
        <div class="row">
            <div class="col-sm-12">

                <div class="wrap">

                    <h2>Laravel Multiple Image Upload Example</h2>

                    @if ($message = Session::get('success'))
                        <div class="alert alert-success alert-block">
                            <button type="button" class="close" data-dismiss="alert">×</button>
                            <strong>{{ $message }}</strong>

                        @foreach(Session::get('image') as $img)
                            <img src="images/{{ $img }}" style="width:100px;">

                    @if (count($errors) > 0)
                        <div class="alert alert-danger">
                            <strong>Whoops!</strong> There were some problems with your file.
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>

                    <form action="{{ URL::to('/upload-image') }}" method="POST" enctype="multipart/form-data">
                        <div class="row">
                            <div class="col-md-6">
                            <input type="file" name="upload[]" multiple>
                            <div class="col-md-6">
                                <button type="submit" class="btn btn-info">Upload</button>




Use the Artisan serve command to run the Laravel application.

php artisan serve

This will start the Laravel Development Server, After that, you can use “” in your browser to access your application.

Laravel Multiple Image Upload


Final Word’s

I hope you have enjoyed this tutorial, Today we’ve explored  “Handling Multiple File Upload in Laravel”.

We will discuss more on the file uploading such as image watermark, resize images, and many more in our coming tutorials. Please feel free to add a comment if any queries.

Keep Learning, Stay Safe 🙂


If you like our content, please consider buying us a coffee.
Thank you for your support!
Buy Me a Coffee

Get real time updates directly on you device, subscribe now.

1 Comment
  1. Lucas says

    So helpful! Thanks man!

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More