Forum Moderators: coopster
I can't easily think of a way to do this. Maybe with AJAX?
Any suggestions?
Right now the form submits post data to a php script. I think to use AJAX I'd need the form to use javascript to asyncronously submit the post data to the php script (maybe?) but I still don't know how php would communicate load progress.
I ended up throwing something together that works ok, but it's pretty minimal. All it does is tell the user that their upload is still working (doesn't say file size, speed, etc.) If you like, I can list the code here, perhaps other folks might be able to expound on it.
<edit>I got the basics of this code from <snip></edit>
Basically, it searches the upload_temp_dir for phpWhatever files, checks a database listing to see if anybody else "owns" that file, then uses the filesize() command to get the currently uploaded bytes everytime the page is reloaded, so it could work with AJAX fairly well.
-sned
(I have a meeting from 10:30 to infinity coming up, so might be a bit before I can post the code).
[edited by: dreamcatcher at 10:59 pm (utc) on Nov. 1, 2006]
[edit reason] No URLs, thanks. [/edit]
So this is how it would work?
1)On form submit, call an ajax function that will operate while file loads
2) Ajax function calls a php file that monitors the size of a tmp file on the server, reporting back
3) When orignal php post page finishes, it will load in browser with results
Issues:
From what the site above mentions, it is hard to know the name of the tmp file, and thus you want to make sure only one tmp file is present? I'll look into the details of this and report back, as this creates imprecision I'm not comfortable with and limits # of uploads.
1) On form submittal*, the script gets ALL the files from the tmp directory.
2) The script checks each file against a database table. Temporary file names are tied to a session id in the database. My thoughts are that if a file is already in the database, somebody else is uploading it, so I don't need to track that file, but if it's not in the database, or it has my session id, then I need to track that file.
3) To track "completion" of the file upload, I check time() vs filemtime(). After a certain margin, I assume that the file upload is done and move on to the next file uploaded (this assumes that there are multiple files uploaded by the same user at the same time).
4) When the processing script is done (uploaded files are modified, copied, etc), I delete all entries associated with the session id from the database.
Of course, none of this is exact. It could possibly pick up a file another user is uploading, if two users submit at the exact same time. All I wanted to do was give the users an indication that their upload was progressing.
* As I was thinking of this, I realized that I open a popup window on form submission to track the uploads ... if that popup window doesn't work right the first time (times out - our network connection here is horrible), the script won't start, which could lead to problems later on.... I think I need to do a redirect or something which doesn't require a trip back to the client, perhaps exec a system command ...
On another side, I thought I had it easily figured out: I would just ini_set the upload_tmp_dir for each separate session, then remove that directory when finished. However, you can't change the upload_tmp_dir setting with ini_set ... oh well.
[development.finetooth.com...]
This is actually one of the best upload bars I`ve seen.
dc