'Your PHP version does not support unzip functionality.'); return false; } $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(); $GLOBALS['status'] = array('success' => 'Files unzipped successfully'); return true; }else{ $GLOBALS['status'] = array('error' => 'Directory not writeable by webserver.'); return false; } }else{ $GLOBALS['status'] = array('error' => 'Cannot read .zip archive.'); return false; } } /** * Decompress a .gz File. * * @param $archive * @param $destination */ public static function extractGzipFile($archive, $destination){ // Check if zlib is enabled if(!function_exists('gzopen')){ $GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.'); return false; } $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)){ $GLOBALS['status'] = array('success' => 'File unzipped successfully.'); return true; }else{ $GLOBALS['status'] = array('error' => 'Error unzipping file.'); return false; } } /** * Decompress/extract a Rar archive using RarArchive. * * @param $archive * @param $destination */ public static function extractRarArchive($archive, $destination){ // Check if webserver supports unzipping. if(!class_exists('RarArchive')){ $GLOBALS['status'] = array('error' => 'Your PHP version does not support .rar archive functionality.'); return false; } // Check if archive is readable. if($rar = \RarArchive::open($archive)){ // Check if destination is writable if (is_writeable($destination . '/')) { $entries = $rar->getEntries(); foreach ($entries as $entry) { $entry->extract($destination); } $rar->close(); $GLOBALS['status'] = array('success' => 'File extracted successfully.'); return true; }else{ $GLOBALS['status'] = array('error' => 'Directory not writeable by webserver.'); return false; } }else{ $GLOBALS['status'] = array('error' => 'Cannot read .rar archive.'); return false; } } } ?>