PHP progress bar for uploads
Transferring files from a client (e.g. a browser ) to a server (e.g. a web server ) is a default feature of nowadays internet applications. Due to the raising amount of hight speed internet connections (e.g. DSL ) the average size of uploaded files also raises. In case of internet connections with low bandwidth or too large files sizes, a user would like to know how much of a file has already been transferred. As far as the internet application can make use of PHP, the extenion PHP upload progress can be used to show the user how many percent of a file have already been transferred. The extension is based on the work of Doru Petrescu and Christian Stocker and is written in the programing language C .
A latest version of the PHP upload progress extension is available on the central download page.
Documentation
The extension adds a new function uploadprogress_get_info that can be used within a PHP script. This function expects an ID as the only parameter. This ID is a key identifying an upload process uniquely. The key has to be created dynamically for each upload by passing it within a hidden input field. The name of this hidden input field can be configured using a setting in the php.ini file. The form could for example look like this.
After sending this kind of form, the progress of the upload can be tracked using the function uploadprogress_get_info. Therefore the same value that has been provided as "<?php rand() . time(); ?>" /> in the example above, has to be passed to the function. To accomplish this, there exist several possibilities that should not be discussed here in detail. The extension contains an example showing one of those possibilities.
The function returns an array. This array stores the following information.
| Name | Description |
| bytes_total | Amount of bytes that should be uploaded in total |
| bytes_uploaded | Amount of bytes that have been uploaded so far |
| speed_average | Current average upload speed |
| est_sec | Estimated time the upload will finished |
| current_file | Name of the file that is currently uploaded |
Configuration
The extension can be configured using several parameters. The configuration can be done in the file php.ini (or in one the files included by it) or in the configuration file of the web server. The following parameters are currently supported.
| Parameter | Type | Default setting | Description |
| uploadprogress.filename_template | String | /tmp/upt_%s.txt | Name of the file storing the upload progress information |
| uploadprogress.upload_identifier | Strting | UPLOAD_IDENTIFIER | Name of the hidden input field (in the upload form) identifying the upload uniquely |
| uploadprogress.update_interval | Integer | 500 | Values that defines how often the upload progress values are calculated |
| uploadprogress.delete_finished | Boolean | 1 | If this value is set to one, the temporary file storing the upload progress values will be deleted after the upload is finished |
Links
As a starting point for the development of the extension I have used and adjusted the following solution that already existed:
