Jump to content

extract status


hackalive

Recommended Posts

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.

Link to comment
Share on other sites

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.";
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.