function findFromZip($file, $path) { global $encoding; if (preg_match('/.*\\.(?:jar|zip)$/i', $file)) { if (function_exists("zip_open")) { $zip = zip_open($file); if (!is_resource($zip)) { die(zipFileErrMsg($zip)); } while ($entry = zip_read($zip)) { if (zip_entry_name($entry) == $path && zip_entry_open($zip, $entry, "r")) { $contentType = findMimiType($path); if (preg_match('/^image\\//i', $contentType)) { header("Content-Type:{$contentType};"); } else { header("Content-Type:{$contentType};charset={$encoding}"); } echo zip_entry_read($entry, zip_entry_filesize($entry)); zip_entry_close($entry); zip_close($zip); return true; } } zip_close($zip); } else { echo "//您的php没有安装zip扩展,无法遍历zip格式类库"; return true; } } }
function unzip_archive($local_archive, $restore_path_base) { // First we clear the directory utility_recursive_rmdir($restore_path_base); //echo "local_archive=[". $local_archive ."]<br />"; //echo "restore_path_base=[". $restore_path_base ."]<br />"; //die(); if (!file_exists($local_archive)) { echo "Archive file [". $local_archive ."] does not exist<br />"; die(); } $zip_filesize = filesize($local_archive); //echo "zip_filesize=[". $zip_filesize ."]<br />"; //die(); @ini_set('memory_limit', $zip_filesize*3); @set_time_limit(0); $zip_fp = zip_open($local_archive); if (!is_resource($zip_fp)) { echo "Unable to open local archive [". $local_archive ."] ". zipFileErrMsg($zip_fp) ."<br />"; die(); } while ($zip_entry = zip_read($zip_fp)) { $zip_entry_filename = zip_entry_name($zip_entry); //echo "zip_entry_filename=[". $zip_entry_filename ."]<br />"; $local_filename = $restore_path_base . $zip_entry_filename; // Is entry a directory? if (substr($local_filename, -1) == "/") { if (!file_exists($local_filename)) { mkdir($local_filename, 0777, true); } continue; } // Else just process the files $local_filepath = dirname($local_filename); if (!file_exists($local_filepath)) { mkdir($local_filepath, 0777, true); } if (file_exists($local_filename)) { @unlink($local_filename); } $local_file_fp = fopen($local_filename, "w"); if (zip_entry_open($zip_fp, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($local_file_fp, $buf); zip_entry_close($zip_entry); fclose($local_file_fp); } } zip_close($zip_fp); }
function themify_extract_zip($file) { $zip = zip_open($file); $dir = "temp/"; if (is_resource($zip)) { while ($zip_entry = zip_read($zip)) { // echo $dir.basename(zip_entry_name($zip_entry)); $fp = fopen($dir . basename(zip_entry_name($zip_entry)), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp, "{$buf}"); zip_entry_close($zip_entry); fclose($fp); } } zip_close($zip); } else { echo zipFileErrMsg($zip); } if (file_exists($dir . "custom-config.xml")) { unlink("../custom-config.xml"); rename($dir . "custom-config.xml", "../custom-config.xml"); } if (file_exists($dir . "custom-modules.php")) { unlink("../custom-modules.php"); rename($dir . "custom-modules.php", "../custom-modules.php"); } if (file_exists($dir . "custom-functions.php")) { unlink("../custom-functions.php"); rename($dir . "custom-functions.php", "../custom-functions.php"); } if (file_exists($dir . "data_export.txt")) { $handler = fopen($dir . "data_export.txt", "r"); $data = fread($handler, filesize($dir . "data_export.txt")); themify_set_data(unserialize($data)); fclose($handler); } }