open($tempfile); $rootStat = $zip->statIndex(0); // Write version $version = substr($rootStat['name'], strrpos($rootStat['name'], '-') + 1, -1); echo "version $version\n"; file_put_contents("version.txt", $version); for ($i = 1; $i < $zip->numFiles; $i++) { $stat = $zip->statIndex($i); // Strip name $name = substr($stat['name'], strlen($rootStat['name'])); if (substr($name, -1) == '/') { // Directory $tname = $target.$name; if (substr_count($name, '/') == 1) { // Initial directory echo "clean $name\n"; @rrmdir($tname); } echo "mkdir $name\n"; mkdir($tname); } else { // Extract file echo "extract $name\n"; $fpIn = $zip->getStream($stat['name']); $fpOut = fopen($target.$name, 'w'); while ($data = fread($fpIn, 1024)) { fwrite($fpOut, $data); } fclose($fpIn); fclose($fpOut); } } // Clean up echo "cleanup\n"; unlink($tempfile);