public function install($path = "./") { if ($this->details != null && is_writable($path)) { if (copy($this->details["Route"], $path . $this->details["File"])) { if ($this->details["Hash"] == md5_file($this->details["File"])) { $zip = new ZipArchive(); if ($zip->setPassword("MySecretPassword")) { if ($zip->open($data["File"]) === true) { $zip->extractTo($path); $zip->close(); unlink($data["File"]); return true; } else { return false; } } } else { return false; } } else { return false; } } else { throw new RuntimeException("Installation path [{$path}] is not writable."); } }
/** * ZipArchiveクラスを利用した解凍 * * @param string $path Zipファイルパス * @return bool */ protected function _extractWithZipArchiveClass($path) { $encodeCharset = "UTF-8"; // server os のファイルシステム文字コード mb_language('Japanese'); setlocale(LC_ALL, 'ja_JP.UTF-8'); // スレッドセーフじゃないので直前で $zip = new ZipArchive(); $result = $zip->open($this->_zipPath); if ($result !== true) { return false; } if ($this->_password) { $zip->setPassword($this->_password); } $index = 0; while ($zipEntry = $zip->statIndex($index)) { $zipEntryName = $zipEntry['name']; $destName = mb_convert_encoding($zipEntry['name'], $encodeCharset, 'auto'); if ($zip->renameName($zipEntryName, $destName) === false) { return false; } if ($zip->extractTo($path, $destName) === false) { return false; } if ($zip->renameName($destName, $zipEntryName) === false) { return false; } $index++; } $zip->close(); return true; }
}); get('/extract', function () { $path = 'Z:\\POS_BACK\\2015\\'; //$files = scandir($dir); $dirs = array_diff(scandir($path), array('..', '.')); foreach ($dirs as $dir) { $files = array_diff(scandir($path . $dir), array('..', '.')); //echo count($files).'<br>'; if (count($files) > 0) { echo $path . $dir . ' - ' . $files[count($files)] . '<br>'; $zip = new ZipArchive(); $zip_status = $zip->open($path . $dir . '\\' . $files[count($files)]); echo $zip_status . '<br>'; if ($zip_status === true) { echo 'extracting<br>'; if ($zip->setPassword("admate")) { $path2 = public_path() . '\\dbf\\' . $dir . '\\'; if (!file_exists($path)) { mkdir($path, 0777, true); } if (!$zip->extractTo($path2)) { echo "Extraction failed (wrong password?)"; } echo 'extracted to ' . $path2 . '<br>'; } $zip->close(); } else { die("Failed opening archive: " . @$zip->getStatusString() . " (code: " . $zip_status . ")"); } } else { echo $dir . ' - no dir <br>';
public function zipData() { $log = vglobal('log'); $log->debug('Start ' . __CLASS__ . ':' . __FUNCTION__); $dbFiles = $this->getFilesStructure(); $zip = new ZipArchive(); $destination = $this->tempDir . '/' . $this->get('filename') . '.files.zip'; $count = 1; $allFiles = $this->get('allfiles'); $mainConfig = $this->getConfig('main'); $maxTime = ini_get('max_execution_time') * 0.5; $startTime = self::getTime(); $singleMode = $mainConfig['type'] == 'true'; // Overall mode or Single mode if ($zip->open($destination, ZIPARCHIVE::CREATE) && $allFiles != 0) { foreach ($dbFiles as $id => $path) { $start = self::getTime(); if (is_dir($path)) { $zip->addEmptyDir($path . '/'); } elseif (is_file($path)) { $zip->addFile($path, $path); } $this->markFile($id); $this->updateProgress('5', $count / $allFiles * 100, self::getTime() - $start); $count++; if ($singleMode && self::getTime() - $startTime >= $maxTime) { continue; } } if (vglobal('encryptBackup') && version_compare(PHP_VERSION, '5.6.0') >= 0) { $code = $zip->setPassword(AppConfig::securityKeys('backupPassword')); if ($code === true) { $log->debug('Backup files password protection is enabled'); } else { $log->error('Has not been possible password protect your backup files'); } } $zip->close(); } $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__); }