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
https://forums.phpfreaks.com/topic/222966-extract-status/
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
https://forums.phpfreaks.com/topic/222966-extract-status/#findComment-1152844
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
https://forums.phpfreaks.com/topic/222966-extract-status/#findComment-1154993
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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