How can I create a file upload progress bar with PHP and jQuery? Please don't refer me to Flash stuff like Uploadify. I want to create my own.
4 Answers
Just store and update the progress in server side session and use repeated ajaxical calls from the client side on to obtain the current progress from the server side session until it gets 100%. Long story short, here's a clear tutorial how to do it with PHP and jQuery: How to build an ajax progress bar with jQuery and PHP.
Then the server side part, you need at least PHP 5.2 for this with the PECL Uploadprogress extension. You can find here a blog about it: PECL Uploadprogress example. This comment of jazfresh on php.net is also helpful.
2 Comments
Basically you'll need to control how much data is sent in some time span. As you don't control your browser data transfer, neither how your browser read data from your file, you can't do that with plain Javascript.
You'll need some 3rd party control, like Silverlight, Flash or Java applets. Using them you'll have granted that filesystem access, so you can control how to read your source file. So, to build your progress bar, you just need to make several HTTP calls to your server application sending your source file in small pieces.
Comments
To get file(s) upload progress you should use Flash. A tutorial with more info can be found here. Note that this is using .NET though, not PHP.