PHP - File upload progress bar with percentage using form jquery example

By Hardik Savani | May 19, 2016 | Category : PHP jQuery

Sometimes we require to show progress bar with percentage on file upload, because sometimes if we upload large size of file then we should too much wait without known perfect time. So at that time if we add progress bar with percentage then it is more comfort then other, that way user can see how much time it will take and how much upload.

In this example i going to give you File upload progress bar with percentage using form jquery example in php. in this example i use form js that way we can upload using ajax and we don't need to page refresh. in this example you have to create only two file one index.php and other one uploadpro.php this is much easy. After this example you will find bellow preview:



<html lang="en">


<title>File upload progress bar with percentage using form jquery example</title>

<link rel="stylesheet" href="" >

<script src=""></script>

<script src=""></script>


$(document).ready(function() {

var progressbar = $('.progress-bar');




target: '.preview',

beforeSend: function() {





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

progressbar.width(percentComplete + '%');

progressbar.text(percentComplete + '%');









<nav class="navbar navbar-default">

<div class="container-fluid text-center">

<div class="navbar-header">

<a class="navbar-brand" href="#"></a>




<div class="container text-center">

<h2>PHP - File upload progress bar and percentage with jquery</h2>

<div style="border: 1px solid #a1a1a1;text-align: center;width: 500px;padding:30px;margin:0px auto">

<form action="uploadpro.php" enctype="multipart/form-data" class="form-horizontal" method="post">

<div class="preview"></div>

<div class="progress" style="display:none">

<div class="progress-bar" role="progressbar" aria-valuenow="0"

aria-valuemin="0" aria-valuemax="100" style="width:0%">




<input type="file" name="image" class="form-control" />

<button class="btn btn-primary upload-image">Upload Image</button>








define('DB_SERVER', 'localhost');

define('DB_USERNAME', 'root');

define('DB_PASSWORD', 'root');

define('DB_DATABASE', 'learn');


if(isset($_POST) && !empty($_FILES['image']['name'])){

$name = $_FILES['image']['name'];

list($txt, $ext) = explode(".", $name);

$image_name = time().".".$ext;

$tmp = $_FILES['image']['tmp_name'];

if(move_uploaded_file($tmp, 'upload/'.$image_name)){

mysqli_query($db,"INSERT INTO items (title)

VALUES ('".$image_name."')");

echo "<img width='200px' src='upload/".$image_name."' class='preview'>";


echo "image uploading failed";




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.