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

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

In this post we will give you information about PHP – File upload progress bar with percentage using form jquery example. Hear we will give you detail about PHP – File upload progress bar with percentage using form jquery exampleAnd how to use it also give you demo for it if it is necessary.

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:

Preview:

index.php

<html lang="en">

<head>

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

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

<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>

$(document).ready(function() {


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


$(".upload-image").click(function(){

$(".form-horizontal").ajaxForm(

{

target: '.preview',

beforeSend: function() {

$(".progress").css("display","block");

progressbar.width('0%');

progressbar.text('0%');

},

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

progressbar.width(percentComplete + '%');

progressbar.text(percentComplete + '%');

},

})

.submit();

});


});

</script>

</head>

<body>

<nav >

<div >

<div >

<a href="#">ItSolutionstuff.com</a>

</div>

</div>

</nav>

<div >

<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" method="post">


<div ></div>

<div style="display:none">

<div role="progressbar" aria-valuenow="0"

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

0%

</div>

</div>


<input type="file" name="image" />

<button >Upload Image</button>


</form>

</div>

</div>

</body>

</html>

uploadpro.php

<?php

define('DB_SERVER', 'localhost');

define('DB_USERNAME', 'root');

define('DB_PASSWORD', 'root');

define('DB_DATABASE', 'learn');

$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);

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'>";

}else{

echo "image uploading failed";

}

}

?>

Hope this code and post will helped you for implement PHP – File upload progress bar with percentage using form jquery example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

4  +    =  8

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US