localdir)) { while (($file = readdir($dh)) !== FALSE) { if (pathinfo($file, PATHINFO_EXTENSION) === 'zip' || pathinfo($file, PATHINFO_EXTENSION) === 'gz' ) { $this->zipfiles[] = $file; } } closedir($dh); if(!empty($this->zipfiles)) { self::$status = '.zip or .gz files found, ready for extraction'; } else { self::$status = 'Error: No .zip or .gz files found.'; } } //check if an archive was selected for unzipping //check if archive has been selected $input = ''; $input = strip_tags($_POST['zipfile']); //allow only local existing archives to extract if ($input !== '') { if (in_array($input, $this->zipfiles)) { self::extract($input, $this->localdir); } } } public static function extract($archive, $destination) { $ext = pathinfo($archive, PATHINFO_EXTENSION); if ($ext === 'zip') { self::extractZipArchive($archive, $destination); } else { if ($ext === 'gz') { self::extractGzipFile($archive, $destination); } } } /** * Decompress/extract a zip archive using ZipArchive. * * @param $archive * @param $destination */ public static function extractZipArchive($archive, $destination) { // Check if webserver supports unzipping. if(!class_exists('ZipArchive')) { self::$status = 'Error: Your PHP version does not support unzip functionality.'; return; } $zip = new ZipArchive; // Check if archive is readable. if ($zip->open($archive) === TRUE) { // Check if destination is writable if(is_writeable($destination . '/')) { $zip->extractTo($destination); $zip->close(); self::$status = 'Files unzipped successfully'; } else { self::$status = 'Error: Directory not writeable by webserver.'; } } else { self::$status = 'Error: Cannot read .zip archive.'; } } /** * 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 = 'Error: Your PHP has no zlib support enabled.'; 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 = 'File unzipped successfully.'; } else { self::$status = 'Error unzipping file.'; } } } ?> File Unzipper

Archive Unzipper

Select .zip archive or .gz file you want to extract:


Status:
Processingtime: ms