File uploads - progress reporting gets stuck short of 100%
- From: John Geddes <john@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 07 May 2008 22:06:09 +0100
AIUI PHP 5.2 provides hooks for monitoring file upload progress, but you need an extension to access the data.
I've tried both the PERC "uploadprogress" and "apc" extensions for creating a progress bar during a file upload. With both I hit the same problem - can anyone help?
Both extensions involve repeated AJAX (http or iFrame) calls to a progress-checking php page, which uses an extension-specific function to return (among other things) the bytes uploaded so far, and the size of the file in bytes.
As the initial file upload progresses, up goes the percentage ... until shortly before 100%. But once the file is uploaded, it needs to be moved (and checked) from its temporary location - or else it will be deleted when the upload-form-processing page closes. And this is where the problem is. I want to be able to show when uploading is complete, and replace the progress bar with the status "Processing" until the whole process is finished. But that isn't as easy as it seems.
PHP (at least as it runs on my WAMP setup) seems to refuse calls to the progress-checking page whilst the operation "move_uploaded_file" is taking place. And with a large file (or, presumably, modest sized files on a busy server), that operation takes quite a while. During this time, the user has seen the progress bar whizz up from zero to say 95% (the value returned on the last progress-check before the file was finished), but then sees progress appear to stick at 95%. Only when the "move_uploaded_file" operation is complete will php process the progress-checking page calls - and at that point, the progress can be updated to show the file fully uploaded. But it looks dreadful, and an impatient user might give up having presumed that something had gone wrong.
I've tried a "sleep" for 5 seconds before the move_uploaded_file operation, but that too locks out the progress-checking page.
Are there any php.ini settings that will change this? Is there any other way to report back that the initial upload is finished before the move_uploaded_file is complete?
The least-bad solution I've found is to do a "rename" rather than a "move_uploaded_file" - it seems considerably quicker so the unwanted effect is less pronounced. But this has security implications.
Ideas?
John Geddes
England.
.
- Follow-Ups:
- Re: File uploads - progress reporting gets stuck short of 100%
- From: Jerry Stuckle
- Re: File uploads - progress reporting gets stuck short of 100%
- Prev by Date: AS3 Flash panel PHP MySQL extension
- Next by Date: Re: File uploads - progress reporting gets stuck short of 100%
- Previous by thread: AS3 Flash panel PHP MySQL extension
- Next by thread: Re: File uploads - progress reporting gets stuck short of 100%
- Index(es):
Relevant Pages
|