/** * Decompress a .gz File. * * @param $archive * @param $destination */ public static function extractGzipFile($archive, $destination) { // Check if zlib is enabled if (!function_exists('gzopen')) { self::$status = '<span style="color:red; font-weight:bold;font-size:120%;">Error: Your PHP has no zlib support enabled.</span>'; return; } $filename = pathinfo($archive, PATHINFO_FILENAME); $gzipped = gzopen($archive, "rb"); $file = fopen($filename, "w"); while ($string = gzread($gzipped, 4096)) { fwrite($file, $string, strlen($string)); } gzclose($gzipped); fclose($file); // Check if file was extracted. if (file_exists($destination . '/' . $filename)) { self::$status = '<span style="color:green; font-weight:bold;font-size:120%;">File unzipped successfully.</span>'; } else { self::$status = '<span style="color:red; font-weight:bold;font-size:120%;">Error unzipping file.</span>'; } }
/** * valid module package by zip * @param $file * @return bool */ static function check_module_zipfile($file) { $dirs = HW_Unzipper::get_root_dirs_fromzip($file); $files = HW_Unzipper::get_root_files_fromzip($file); if (!count($dirs) || count($dirs) > 1 || count($files)) { return false; } return !in_array($dirs[0], array_values(HW_File_Directory::list_folders(HW_HOANGWEB_PLUGINS))); }