File uploads - progress reporting gets stuck short of 100%



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.
.



Relevant Pages

  • Re: [PHP] Re: progress in PHP
    ... Yes perl is used because it gives access to raw post data. ... eliminate the popup and show the progress bar in a frame you don't need ... > Because PHP does not provide support to handle the raw HTTP request. ... there is no way to handle upload progress with a PHP only ...
    (php.general)
  • Re: [PHP] Re: progress in PHP
    ... The problem is not showing progress but rather tracking progress. ... What you seem to not be understanding is that PHP handles uploads ... by the time a PHP script that gets the submitted upload ... The Perl solution is based on a script that handles and tracks the ...
    (php.general)
  • Re: File uploads - progress reporting gets stuck short of 100%
    ... I've tried both the PERC "uploadprogress" and "apc" extensions for creating a progress bar during a file upload. ... Both extensions involve repeated AJAX calls to a progress-checking php page, which uses an extension-specific function to return the bytes uploaded so far, and the size of the file in bytes. ... 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. ...
    (alt.php)
  • Re: [PHP] Re: progress in PHP
    ... here is a link to a PHP extension which enables the ability to ... track the progress of a PHP upload. ... >> How does perl show progress of the upload if it is a server side scripting ...
    (php.general)
  • Re: [PHP] Re: progress in PHP
    ... > How does perl show progress of the upload if it is a server side scripting ... Because PHP does not provide support to handle the raw HTTP request. ... OTOH, Perl ... >>php approach to displaying a progress bar. ...
    (php.general)