note 71564 added to features.file-upload
| From: | jazfreshathotmail dot com at osu1 dot php dot net | Date: | Wed, 06 Dec 2006 07:45:16 +0000 |
| Subject: | note 71564 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120329@lists.php.net to get a copy of this message | ||
Now that PHP 5.2 supports a hook that can be used to handle upload progress, you can use a PECL
extension (uploadprogress) to display an upload progress meter. Since documentation for this PECL
extension is a bit thin on the ground, here are the basics:
1) Run "pecl install uploadprogress", and add "extension=uploadprogress.so" in
your php.ini file.
2) Tell the extension where to temporarily store information about each upload. By default, this is
in "/tmp/upt_%s.txt" (where %s is replaced with the UPLOAD_IDENTIFIER, see below). You can
change it with the following config line:
uploadprogress.file.filename_template = /path/to/some_name_%s.txt
It must have a single '%s' in it, or it will fail!
3) Add a hidden element at the very beginning (this is important) of your upload form, called
UPLOAD_IDENTIFIER. The value of this should be match the expression
"^[A-Za-z0-9_.-=]{1,64}$" and be unique for every upload.
4) When the form is submitted, pop open a window to display the progress information and continue
submitting the form. This window should refresh itself every few seconds, calling a PHP script that
will retrieve the progress information and generate a display meter.
This script calls the function uploadprogress_get_info($id), where $id is the UPLOAD_IDENTIFIER
value. This will return false if there is no progress information, or an array of values about that
upload. The array contains:
time_start - The time that the upload began (same format as time()).
time_last - The time that the progress info was last updated.
speed_average - Average speed. (bytes / second)
speed_last - Last measured speed. (bytes / second)
bytes_uploaded - Number of bytes uploaded so far.
bytes_total - The value of the Content-Length header sent by the browser.
files_uploaded - Number of files uploaded so far.
est_sec - Estimated number of seconds remaining.
The speed_average is measured based on the number of bytes uploaded since the upload began, whereas
the speed_last is based on the number of bytes uploaded since the progress information was last
updated. The progress information is updated whenever PHP reads in some more data from the client,
so speed_last may not be very accurate.
Note 1) The bytes_total figure is NOT a reflection of the file size, but of the POST's size, so
don't expect them to match.
Note 2) This module really only detects how much data the POST form has sent, and keeps a running
count of how many POST variables of type 'file' that it encounters along the way. It has
no way of knowing how many files are in the POST, so it is not possible to have a progress bar for
each file, just one for all files (and the ability to display how many files have been uploaded so
far).
----
Server IP: 210.138.109.182
Probable Submitter: 61.213.152.134 (proxied: Version 1.1-Build_SOL_1126 $Date: 11/10/2005
17:46:0044$(IWSS))
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- https://master.php.net/note/edit/71564
Del: integrated -- https://master.php.net/note/delete/71564/integrated
Del: useless -- https://master.php.net/note/delete/71564/useless
Del: bad code -- https://master.php.net/note/delete/71564/bad+code
Del: spam -- https://master.php.net/note/delete/71564/spam
Del: non-english -- https://master.php.net/note/delete/71564/non-english
Del: in docs -- https://master.php.net/note/delete/71564/in+docs
Del: other reasons-- https://master.php.net/note/delete/71564
Reject -- https://master.php.net/note/reject/71564
Search -- https://master.php.net/manage/user-notes.php