hackalive Posted December 30, 2010 Share Posted December 30, 2010 Okay I now have a working extract ZIP archive script. What I am now looking to do is have a loop which checks the percentage complete the extraction is and at 100% (with no erros) carry out a PHP function. The code so far is (and includes comments on how the new function would be placed): $dir = opendir('temp'); while(false !==($file=readdir($dir))){ if(strpos($file, '.zip',1)){ extractupdate($file); } } function extractupdate($file){ $zip=new ZipArchive; if($zip->open('temp/'.$file) == TRUE){ $update=rtrim($file, ".zip"); $zip->extractTo($_SERVER['DOCUMENT_ROOT']."/update/temp/$update"); $zip->close(); echo "Extraction started."; // Place loop here to run untill 100% extraction completed and then run function "intsallupdate($update);" } else { echo "Failed to start extraction."; } } function installupdate($update){ // installupdate() will now shift the files around as necessary. // NB to PHPFREAKS, no assistance with code for installupdate() is required, only the loop. Cheers. } Many thanks in advance. Quote Link to comment Share on other sites More sharing options...
Sock Puppet Posted December 30, 2010 Share Posted December 30, 2010 Unless I'm mistaken, ZipArchive::extractTo returns true on success and false on failure. You should be able to just do this: $success = $zip->extractTo($_SERVER['DOCUMENT_ROOT']."/update/temp/$update"); $zip->close(); echo "Extraction started."; if($success) { installupdate($update); } else { echo "Error during extraction."; } Quote Link to comment Share on other sites More sharing options...
hackalive Posted December 30, 2010 Author Share Posted December 30, 2010 ill give it ago Quote Link to comment Share on other sites More sharing options...
hackalive Posted December 30, 2010 Author Share Posted December 30, 2010 This is now preventing it from extracting untill the function is run, I need something that detects a completed extraction then runs the function. Quote Link to comment Share on other sites More sharing options...
hackalive Posted December 31, 2010 Author Share Posted December 31, 2010 BUMP Quote Link to comment Share on other sites More sharing options...
hackalive Posted January 2, 2011 Author Share Posted January 2, 2011 no one? Quote Link to comment Share on other sites More sharing options...
hackalive Posted January 3, 2011 Author Share Posted January 3, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
hackalive Posted January 5, 2011 Author Share Posted January 5, 2011 So no one on this forum has any idea? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 5, 2011 Share Posted January 5, 2011 apparently not. or we/they don't understand the question. i have never used zip extraction via PHP. but i would expect the code to stop at this function call until the function call is complete (i.e. the zip extraction has finished): $zip->extractTo($_SERVER['DOCUMENT_ROOT']."/update/temp/$update"); in other words, by the time this code is reached, i would expect the extraction to be complete, hence there would be no reason to check if it is complete: $zip->close(); but if that function 'starts a secondary thread' as it were, i don't know what to tell you... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.