function test_unzip() { mkdir('zipper_test'); file_put_contents('zipper_test/foo.txt', 'Test'); exec('zip -r zipper_test.zip zipper_test'); Zipper::unzip('zipper_test.zip'); $this->assertTrue(file_exists('cache/zip/zipper_test/foo.txt')); $this->assertEquals('Test', file_get_contents('cache/zip/zipper_test/foo.txt')); }
/** * Requires the entry from $_FILES of a zip file. */ public static function install($source) { try { Zipper::unzip($source['tmp_name']); } catch (Exception $e) { self::$error = $e->getMessage(); return false; } $folder = Zipper::find_folder($source['name']); // Get config and verify it if (!file_exists($folder . '/elefant.json')) { self::$error = __('Verification failed: No configuration file found.'); return false; } $conf = json_decode(file_get_contents($folder . '/elefant.json')); if ($conf === false) { self::$error = __('Verification failed: Invalid configuration file.'); return false; } if (!self::verify($conf)) { // self::$error already set by verify() return false; } // Move files over if ($conf->type === 'app') { if (!rename($folder, 'apps/' . $conf->folder)) { self::$error = __('Unable to write to apps folder.'); return false; } chmod_recursive('apps/' . $conf->folder, 0777); } else { if (!rename($folder, 'layouts/' . $conf->folder)) { self::$error = __('Unable to write to layouts folder.'); } chmod_recursive('layouts/' . $conf->folder, 0777); } // Remove the original zip file @unlink($source['tmp_name']); return $conf; }
public function restore($file) { $folder = $this->getFilePath($this); if (file_exists($file)) { Zipper::unzip($file, $folder); $db = new dbMaster(); $db->loadFile($folder . "db.sql", Yii::app()->db->tablePrefix); } else { throw new CHttpException(500, 'The backup file does not exist.'); } }
if (!class_exists('ZipArchive')) { set_message(__('Operations with archives are not available'), 'error'); redirect(FM_URL . '?p=' . urlencode($p)); } if ($unzip != '' && is_file($path . '/' . $unzip)) { $zip_path = $path . '/' . $unzip; //to folder $tofolder = ''; if (isset($_GET['tofolder'])) { $tofolder = pathinfo($zip_path, PATHINFO_FILENAME); if (mkdir_safe($path . '/' . $tofolder, true)) { $path .= '/' . $tofolder; } } $zipper = new Zipper(); $res = $zipper->unzip($zip_path, $path); if ($res) { set_message(__('Archive unpacked')); } else { set_message(__('Archive not unpacked'), 'error'); } } else { set_message(__('File not found'), 'error'); } redirect(FM_URL . '?p=' . urlencode($p)); } // Change Perms if (isset($_POST['chmod']) && !READONLY) { $path = ROOT_PATH; if ($p != '') { $path .= '/' . $p;