Forum Moderators: coopster
Situation
Problem
Want a progress indicator to continuously display how much of the file has been uploaded.
Solution
First - this is much easier in ASP since ASP has built-in support for reading chunks of HTTP requests (which contain the file data) as they come in. AFAIK, PHP is only invoked by the web server once the entire HTTP request (hence all file data) has been received.
Hence it is necessary to intercept the HTTP request before it gets to PHP i.e. at the web-server level.
This will be achieved by writing an apache module/hook (in perl) that is executed by the web server when a file upload begins.
Items required
----------------------------
Sequence of solution
----------------------------
1. user requests upload form
2. php upload form script executes
a. gets unique uploadID from database
The uploadIDs, if left unchecked, will increment out of control. To control this we delete the upload row when we're done, and just in case this hasn't worked, delete entries older than a few days when we start. Then reset the auto_increment to max( uploadID). This method won't keep uploadIDs perfectly as tight as they could be, but will generally control them.
3. user submits form to receive page
a. javascript launches progress indicator page (passing uploadID as GET variable)
4. mod_perl hook invoked
5. mod_perl hook processes upload request
a. updates database : (uploadID, spool file name, totalBytes)
b. starts writing file to disk (/tmp)
6. php progress indicator page continues to refresh
(always passes uploadID to itself)
a. from database, select filenameSpool, totalBytes where uploadID = $uploadID
b. get size of spool file
c. print page depicting proportion of actual file size : total bytes
d. if file doesn’t exist, or total size = uploaded size, set opening window’s location to be the ‘file uploaded’ page (fileList for the current folder I’m guessing)
7. php receive page invoked by web server
a. select filenameSpool, filename, sessionID from upload where uploadID = $_REQUEST[ ‘uploadID’]
b. check $row[ ‘sessionID’] = session_id() (for security - stops naughty users from swapping uploadIDs)
c. moves file to correct location/filename
d. delete from upload where uploadID = $uploadID
Phew, think that's it. Feedback most welcome.
Now, this sounds really interesting! I will be looking forward to see what others might have to say on this topic.