Multiple File Upload in laravel 7 Example Tutorial

Today, We want to share with you Multiple FileUpload in laravel 7 Tutorial.In this post we will show you one or More File Upload in Laravel 7.x and 6.x Example, hear for Laravel 7/6 – Multi ple ImageFile Upload With Validation we will give you demo and example for implement.In this post, we will learn about Laravel More Files Upload Tutorial Example From Scratch with an example.

Multiple File Upload in laravel 7 Tutorial

There are the Following The simple About Upload one or More Images and Files with Validation in Laravel7 Full Information With Example and source code.

As I will cover this Post with live Working example to develop How To Upload Two or More Files in Laravel7, so the Laravel 7 Two or More FileUpload Tutorial is used for this example is following below.

Phase 1: Download Laravel 7

download a new simple copy source code of Laravel App project

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

Phase 2: Add Migration and Model

create database migration for files table

php artisan make:migration create_files_table

Migration:

<?php


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;


class CreateFormsTable extends Migration
{
    public function up()
    {
        Schema::create('files', function (Blueprint $table) {
            $table->increments('id');
            $table->string('filenames');
            $table->timestamps();
        });
    }


    public function down()
    {
        Schema::dropIfExists('files');
    }
}

run commands

php artisan migrate

php artisan make:model File

Phase 3: Make Routes

routes/web.php

Route::get('file','[email protected]');
Route::post('file','[email protected]');

Phase 4: Make Controller

app/Http/Controllers/FileController.php

<?php


namespace App\Http\Controllers;


use Illuminate\Http\Request;


class FileController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('create');
    }


    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {


        $this->validate($request, [
                'filenames' => 'required',
                'filenames.*' => 'mimes:doc,pdf,docx,zip'
        ]);


        if($request->hasfile('filenames'))
         {
            foreach($request->file('filenames') as $file)
            {
                $name = time().'.'.$file->extension();
                $file->move(public_path().'/files/', $name);  
                $data[] = $name;  
            }
         }


         $file= new File();
         $file->filenames=json_encode($data);
         $file->save();


        return back()->with('success', 'Data Your files has been successfully added');
    }
}

Phase 5: Make Blade File

resources/views/create.blade.php

<html lang="en">
<head>
  <title>Laravel 7 Mass File Upload Example</title>
  <script src="jquery/1.9.1/jquery.js"></script>
  <link rel="stylesheet" href="3.3.6/css/bootstrap.min.css">
</head>
<body>


<div class="container lst">


@if (count($errors) > 0)
<div class="alert alert-danger">
    <strong>Sorry!</strong> There were more problems with your HTML input.<br><br>
    <ul>
      @foreach ($errors->all() as $error)
          <li>{{ $error }}</li>
      @endforeach
    </ul>
</div>
@endif


@if(session('success'))
<div class="alert alert-success">
  {{ session('success') }}
</div> 
@endif


<h3 class="well">Laravel 7 Mass Bulk File Upload</h3>
<form method="post" action="{{url('file')}}" enctype="multipart/form-data">
  {{csrf_field()}}


    <div class="input-group hdtuto control-group lst increment" >
      <input type="file" name="filenames[]" class="myfrm bbrp form-control jdk">
      <div class="input-group-btn"> 
        <button class="btn btn-success" type="button"><i class="fldemo glyphicon glyphicon-plus"></i>Add</button>
      </div>
    </div>
    <div class="clone hide">
      <div class="hdtuto control-group lst input-group" style="margin-top:10px">
        <input type="file" name="filenames[]" class="myfrm bbrp form-control jdk">
        <div class="input-group-btn"> 
          <button class="btn btn-danger" type="button"><i class="fldemo glyphicon glyphicon-remove"></i> Remove</button>
        </div>
      </div>
    </div>


    <button type="submit" class="btn btn-success" style="margin-top:10px">Submit</button>


</form>        
</div>


<script type="text/javascript">
    $(document).ready(function() {
      $(".btn-success").click(function(){ 
          var lsthmtl = $(".clone").html();
          $(".increment").after(lsthmtl);
      });
      $("body").on("click",".btn-danger",function(){ 
          $(this).parents(".hdtuto control-group lst").remove();
      });
    });
</script>


</body>
</html>

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 7 Bulk File Upload Tutorial.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to get the browser viewport height and width dimensions?
  2.   Wordpress Open URL in New Tab programmatically
  3.   html5 range slider with 2 handles using jQuery
  4.   File Upload in Laravel 7 Example Tutorial
  5.   PHP Star Triangle Nested using Foreach Loop
  6.   How to Quickly Index New Post In Google Search
  7.   Shorthand comparisons using PHP Ternary Operator
  8.   PHP Generate HTML file into PDF
  9.   How to Check Whether a Variable is Set or Not in laravel blade?
  10.   Vue JS Get index in v-for loop Example with Demo