I've googled for this but didn't find any solution - is there a way to create a progessbar for adding/extracti开发者_如何学Pythonng files to/from zip archive in PHP? Can I get some kind of status message which I can than get with an AJAX request and update the progress bar?
Thanks.
I am trying to do the same thing at the moment; it is mostly* complete (*see issues section below).
The basic concept I use is to have 2 files/processes:
- Scheduler (starts task and can be called to get updates)
- Task (actually completes the task of zipping)
The Scheduler will:
- Create a unique update token and save to cache (APC)
- Call the Task page using curl_multi_exec which is asynchronous, passing update_token
- Return the token in JSON format OR
- Return the contents of the APC under the update_token (in my case this is a simple status array) as JSON
The Task will:
- Update the APC with status, using the update token
- Do the actual work :)
Client-side
You'll need some JavaScript to call the Scheduler, get the token in return, then call the Scheduler, passing update_token, to get updates, and then use these returned values to update the HTML.
** Potential pitfalls**
Sessions can be a problem. If you have the same session you will notice that your browser (or is this Apache?) waits for the first request in the session to complete before returning others. This is why I store in the APC.
Current Issues
The problem with the ZipArchive class is that it appears to all the grunt work in the ->close() method, whilst the addFile method appears to take little to no time to complete.
As a workaround you can close and then reopen the archive at specific byte or file intervals. This actually slows the process of zipping down a little, but in my case this is acceptable, as the visual progress bar is better than just waiting with no indication of what is happening.
精彩评论