3.7 C
New York
Tuesday, February 7, 2023

PHP Laravel File Upload with Progress Bar Example

It would be awesome if you have file uploading progress bar with percentage using jquery form js in php laravel 5, laravel 6, laravel 7 and laravel 8 application. a progress bar is very helpful to show a client how much uploaded done.

You always did file uploading with a normal way and you can do it easily. But when you have a large amount of file size then it takes time to upload on a server. Maybe you can’t reduce time to upload file or image, but you can display a progress bar with a percentage, so the client can understand how much is remaining to upload a file. So, in this tutorial, we will create file upload with a progress bar in laravel 5.

I write step by step tutorial of file upload with progress bar using jquery form js. So, just follow few step and will get layout like as below:


Step 1: Create Routes

In first step, we will add new two routes. One for display view and we will write jquery code in view file. In Second step, we will create POST route for file upload.


Route::get('file-upload', 'FileController@fileUpload');

Route::post('file-upload', 'FileController@fileUploadPost')->name('fileUploadPost');

Step 2: Create FileController

In second step, we need to create FileController controller with fileUpload() and fileUploadPost(). just create new controller and put bellow code on it:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FileController extends Controller



* Show the application dashboard.


* @return \Illuminate\Http\Response


public function fileUpload()


return view('fileUpload');



* Show the application dashboard.


* @return \Illuminate\Http\Response


public function fileUploadPost(Request $request)



'file' => 'required',


$fileName = time().'.'.request()->file->getClientOriginalExtension();

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

return response()->json(['success'=>'You have successfully upload file.']);



Step 3: Create Blade File

In this Last step, we require to create fileUpload.blade.php file and we write code for jquery and show you with progress bar. So you have to simply add bellow code on following path:


<!DOCTYPE html>



<title>Laravel 5.6 - File upload with progress bar - ItSolutionStuff.com</title>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">


.progress { position:relative; width:100%; border: 1px solid #7F98B2; padding: 1px; border-radius: 3px; }

.bar { background-color: #B4F5B4; width:0%; height:25px; border-radius: 3px; }

.percent { position:absolute; display:inline-block; top:3px; left:48%; color: #7F98B2;}




<div class="container">

<div class="card">

<div class="card-header">

<h2>Laravel 5.6 - File upload with progress bar - ItSolutionStuff.com</h2>


<div class="card-body">

<form method="POST" action="{{ route('fileUploadPost') }}" enctype="multipart/form-data">


<div class="form-group">

<input name="file" id="poster" type="file" class="form-control"><br/>

<div class="progress">

<div class="bar"></div >

<div class="percent">0%</div >


<input type="submit" value="Submit" class="btn btn-success">






<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>

<script src="http://malsup.github.com/jquery.form.js"></script>

<script type="text/javascript">

function validate(formData, jqForm, options) {

var form = jqForm[0];

if (!form.file.value) {

alert('File not found');

return false;



(function() {

var bar = $('.bar');

var percent = $('.percent');

var status = $('#status');


beforeSubmit: validate,

beforeSend: function() {


var percentVal = '0%';

var posterValue = $('input[name=file]').fieldValue();




uploadProgress: function(event, position, total, percentComplete) {

var percentVal = percentComplete + '%';




success: function() {

var percentVal = 'Wait, Saving';




complete: function(xhr) {


alert('Uploaded Successfully');

window.location.href = "/file-upload";







After followed successfully you must have to create “files” folder with full permissions, After that you can quick run by following command:

php artisan serve

Now you can open bellow url on your browser:


I hope it can help you…

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles