本文整理汇总了PHP中zip_packer::archive_to_storage方法的典型用法代码示例。如果您正苦于以下问题:PHP zip_packer::archive_to_storage方法的具体用法?PHP zip_packer::archive_to_storage怎么用?PHP zip_packer::archive_to_storage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zip_packer
的用法示例。
在下文中一共展示了zip_packer::archive_to_storage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
break;
case 'zip':
$zipper = new zip_packer();
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
if (!$file->get_parent_directory()) {
$parent_path = '/';
$filepath = '/';
$filename = get_string('files') . '.zip';
} else {
$parent_path = $file->get_parent_directory()->get_filepath();
$filepath = explode('/', trim($file->get_filepath(), '/'));
$filepath = array_pop($filepath);
$filename = $filepath . '.zip';
}
$filename = repository::get_unused_filename($itemid, $parent_path, $filename);
$newfile = $zipper->archive_to_storage(array($filepath => $file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id);
$home_url->param('action', 'browse');
$home_url->param('draftpath', $parent_path);
redirect($home_url, get_string('ziped', 'repository'));
break;
case 'unzip':
$zipper = new zip_packer();
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename);
if ($newfile = $file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $itemid, $draftpath, $USER->id)) {
$str = get_string('unzipped', 'repository');
} else {
$str = get_string('cannotunzip', 'error');
}
$home_url->param('action', 'browse');
$home_url->param('draftpath', $draftpath);
redirect($home_url, $str);
示例2: zip_tempfiles
/**
* Zips all files in the temporary directory
*
* @param string $filename name of resulting zipfile (optional, defaults to portfolio-export.zip)
* @param string $filepath subpath in the filearea (optional, defaults to final)
* @return stored_file|bool resulting stored_file object, or false
*/
public function zip_tempfiles($filename = 'portfolio-export.zip', $filepath = '/final/')
{
$zipper = new zip_packer();
list($contextid, $component, $filearea, $itemid) = array_values($this->get_base_filearea());
if ($newfile = $zipper->archive_to_storage($this->get_tempfiles(), $contextid, $component, $filearea, $itemid, $filepath, $filename, $this->user->id)) {
return $newfile;
}
return false;
}