How to create a file uploader with a progress bar?
So here is what I want in short:
- A PHP/Javascript/AJAX based File Uploader with a Progress bar what shows the percent(ex: 52%) and
<div>
what grows in width as the upload goes on.
And in long:
I would like a solution written in PHP and Javascript(开发者_JAVA技巧Not jQuery), I tried myself but in server side I can't get the file size of the uploading file so I can't calculate the remaining percent.
Maybe there is a way to do it normally but I didn't find any clear ways. What I found is a lots of PHP patches what didn't worked :\ .
At last I tried Uber Uploader what uses Perl, I installed correctly but when I try to upload a file the progress bar is not shown, there are no errors just doesn't works :(.
However I don't really like to use such solutions because it's really messy even if it works, I like to write my own code if it's possible but I don't find any solution yet.
Also there are flash uploaders like pixeline and swfupload , but as I sayed I would like to use PHP and Javascript.
You should use the UploadProgress
extension, along with a jQuery AJAX request that updates your progress bar according to the reply, every x
milliseconds.
Here's the link to the extension: http://pecl.php.net/package/uploadprogress/
Alternatively, it can also be done with APC.
The file size can be obtained when you access the directory or folder of the file and this may be requested separately or when opening the file depending on the language you eventually use. The progress bar types are legally protected items and they have rules for indicating the progress in different ways visually and some are licensable from major suppliers but there are some freeware or shareware versions which may operate on a compatible operating system when allowed.
PHP completely processes file uploads before passing control back to the page.
This creates a problem.
The only real PHP solution I know of involves the use of APC, which adds a hook to PHP that you can access via a second PHP script over AJAX.
精彩评论