本文整理汇总了PHP中ZipArchive::setPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::setPassword方法的具体用法?PHP ZipArchive::setPassword怎么用?PHP ZipArchive::setPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::setPassword方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
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.");
}
}
示例2: _extractWithZipArchiveClass
/**
* 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;
}
示例3: function
});
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>';
示例4: zipData
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__);
}