Hi all its us again, In the past few months we’ve been asked many a times to help improve the progressbar code. We’ve also been referenced by several websites as THE progressbar to use. In all, we felt we owed it to you guys to make it better.
So here we are, after all those emails and bug reports, we finally got down to it. Always good to take a couple of months to have a fresh prespective of things. We ripped out the old code and made it much better and more extensible than its predecessors. So much that we decided it was enough to qualify as a major revision.
Let see whats been done…
- Cleaned up the code, yes its lighter, cleaner faster. (Still lacks documentation though)
- Callbacks! Everyone’s favourite
- Max values, you can now set it to be 150/2000 instead of just a percentage
- Text formats. Show 75/100 or 75% by toggling the
textFormataccordingly - Steps, how many steps to get to your target value
- Step Duration, how long each step lasts
- Webkit (Chrome/Safari) compatibility. More like, Webkit Hacks
Once again, many a thanks for all those who have so generously provided the feature requests as well as bug fixes every now and then. And thanks for all your patience in waiting for this new release. ![]()
If its working for you, drop us a comment and tell us where we can see your stuff!
Download the new jQuery progressbar here: jQuery progressbar
or view the demo here
Thanks for all the comments and feedback! By popular request i’ve added the multi-colored progress bar and fixed some bugs. The new multi-colored bar changes from red to orange and then to green at configurable intervals. Check out the demo!
Since the last update this endeavour has seen comments claiming that it works and sometimes that it doesnt. I’ve tested the demo across Safari, Opera, IE6/7, Firefox and Chrome. Havent found any problem. For those of you who have problems, please do email me the problem.
Download the new jQuery progressbar here: jQuery progressbar
or view the demo here
HOWTO: PHP and jQuery upload progress bar
Author: gaweee | Filed under: development, howtoWith the controllable jQuery Progress Bar, writing a form upload progress bar seems like a piece of cake now. Hypothetically, all we need is to create the bar, poll for the progress of the file upload, derive the new progress bar value (in percentage) and set it.
To do that you need to prepare the php script to do it. By default PHP cant report the progress of upload progress. However people smarter than me have already solved that problem. In 5 mins i’ve found 2 solutions: the Alternative PHP Cache (APC) method as well as the UploadProgress method. Both of them are PECL packages. Because i couldnt get APC to work on my server properly, i’ll document the UploadProgress more in detail here…
pecl install uploadprogress
Once that is done, register the extension to your PHP with the following line in your php.ini
extension=uploadprogress.so
then restart your apache/httpd
<form id="uploadform" enctype="multipart/form-data" method="post"> <input id="progress_key" name="UPLOAD_IDENTIFIER" type="hidden" value="<?= $uuid ?>" /> <input id="ulfile" name="ulfile" type="file" /> <input type="submit" value="Upload" /> <span id="uploadprogressbar" class="progressbar">0%</span> </form>
this creates the form with a file field as well as a unique UPLOAD_IDENTIFIER hidden field that allows our script to check the progress of the form submission.
header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); if (@$_GET['id']) { echo json_encode(uploadprogress_get_info($_GET['id'])); exit(); }
The header no-cache declarations circumvents IE’s cache of the response. Basically this form does nothing but respond with a json encoded string of the uploadprogress_get_info function. The id argument is the same one we used in the form. Think of it as a form-upload-process-id. A typical response looks like this:
{"time_start":"1214384364","time_last":"1214384366","speed_average":"25889","speed_last":"40952","bytes_uploaded" :"51778","bytes_total":"8125518","files_uploaded":"0","est_sec":"311"}
the response encodes a good deal of data about the form submission. most importantly for us: bytes_uploaded and bytes_total
var progress_key = ''; // this sets up the progress bar $(document).ready(function() { $("#uploadprogressbar").progressBar(); }); // fades in the progress bar and starts polling the upload progress after 1.5seconds function beginUpload() { $("#uploadprogressbar").fadeIn(); setTimeout("showUpload()", 1500); } // uses ajax to poll the uploadprogress.php page with the id // deserializes the json string, and computes the percentage (integer) // update the jQuery progress bar // sets a timer for the next poll in 750ms function showUpload() { $.get("uploadprogress.php?id=" + progress_key, function(data) { if (!data) return; var response; eval ("response = " + data); if (!response) return; var percentage = Math.floor(100 * parseInt(response['bytes_uploaded']) / parseInt(response['bytes_total'])); $("#uploadprogressbar").progressBar(percentage); }); setTimeout("showUpload()", 750); }
viola! read the comments if you dont understand the code. it is _THAT_ straightforward. Of course there can be many improvements such as stopping the script when the upload reaches 100% but thats probably not really needed since the whole page is refreshed. But this approach allows the flexibility of ajax submissions and what nots.
Again, download the jQuery progressbar here: jQuery progressbar
or view the demo here
- Change the HTML hidden form field name from UPLOAD_IDENTIFIER to APC_UPLOAD_PROGRESS
- Change the PHP uploadprogress_get_info($_GET['id']) to apc_fetch(‘upload_’.$_GET['id']));
- Change the Javascript percentage calculation from:
Math.floor(100 * parseInt(response['bytes_uploaded']) / parseInt(response['bytes_total']));
to:
Math.floor(100 * parseInt(response['current']) / parseInt(response['total']));
JQuery Progress Bar 1.1
Author: gaweee | Filed under: developmentThis code has been downloaded quite abit so i thought i’d put in some effort to improve it. I found some free time this evening to clean up the code. The original code is a couple of months old and its my first jquery plugin. I didnt quite understand what i was doing then.I made the code less resource intensive and more configurable.
The progress bar can now be controlled externally. click on the demo link below to see what i’m talking about. I’ll know of at least 1 bug in the script if its fully tested, will try to fix this within the week. Meanwhile if you have any ideas for improvements, please leave a comment!
Download the jQuery progressbar here: jQuery progressbar
or view the demo here
JQuery Progress Bar v1.0
Author: gaweee | Filed under: developmentI really liked the mootools progressbar at http://www.webappers.com/progressBar/ but i’m so against the idea of having 2-3 libraries in a single system. Since i always use jQuery, i tried to port the progressBar over. The problem is, jQuery unlike most of the other libraries doesnt quite work with objects. So its not that easy to return and manage an object to perform actions like “add 5%”, “fill to 95%”, etc. Honestly i’m not sure where else to use such a comprehensive progress bar other than a file upload utility.
So for what its worth, i made a simple progress bar in jQuery that parses a percentage string and animates the loading.
Download the jQuery progressbar here: jQuery progressbar
Or view the demo: here
Most Popular
- HOWTO: PHP and jQuery upload progress bar (48)
- JQuery Progress Bar 1.1 (42)
- Howto: Repackageable custom extension development in Magento - Part 2 - Admin Controller (24)
- Howto: Repackageable custom extension development in Magento - Part 8 - CRUD - Update (16)
- HOWTO: struts 2 i18n (13)
- JQuery Progress Bar 2.0 (12)
- JQuery Progress Bar 1.2 (11)
- Howto: Repackageable custom extension development in Magento (9)
- Howto: Repackageable custom extension development in Magento - Part 3 - Database (9)
- Howto: Repackageable custom extension development in Magento - Part 9 - Frontend - List (8)
Recent Comments
- learning methods: All the posts you talk
- best travel agency: Wow! I really enjoyed this
- Muzafar Ali: Hi, thanks for sharing a beautiful
- andy65007: After the progress bar
- Mark: Excellent tutorials. Most "how to
- Mark: As Jim said before, you
- Jeremy Roberts: I tried and it works
- Silas Nordes: Came to this site by
- 150cc mopeds: That was a superb blog
- Jason: if the situation is like
Latest Entries
- jQuery Progress Bar Configuration
- Extracting email addresses from inbox
- 10 Good (Free and Legal) Source for Photos and Images
- Howto: Backup Microsoft SQL Server Database, as in Dump it to a SQL Script (like MYSQL's sqldump)
- Managing client's expectation with wireframe software
- Howto: Repackageable custom extension development in Magento - Part 9 - Frontend - List
- JQuery Progress Bar 2.0
- HOWTO: Find icons for your new prototype system
- Google Maps Helper
- laying the cornerstones
