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);
/** * 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; }