mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-32639 files: Improved File Manager download and zip support
This commit is contained in:
parent
697ade2850
commit
638d72cd0b
6 changed files with 46 additions and 26 deletions
|
@ -139,17 +139,17 @@ case 'downloaddir':
|
|||
$zipper = new zip_packer();
|
||||
|
||||
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
|
||||
if ($file->get_parent_directory()) {
|
||||
$parent_path = $file->get_parent_directory()->get_filepath();
|
||||
$filename = trim($draftpath, '/').'.zip';
|
||||
} else {
|
||||
$parent_path = '/';
|
||||
if ($draftpath === '/') {
|
||||
$filename = get_string('files').'.zip';
|
||||
} else {
|
||||
$filename = explode('/', trim($draftpath, '/'));
|
||||
$filename = array_pop($filename) . '.zip';
|
||||
}
|
||||
|
||||
if ($newfile = $zipper->archive_to_storage(array('/' => $file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id)) {
|
||||
$fileurl = moodle_url::make_draftfile_url($itemid, '/', $filename)->out();
|
||||
header('Location: ' . $fileurl );
|
||||
$newdraftitemid = file_get_unused_draft_itemid();
|
||||
if ($newfile = $zipper->archive_to_storage(array('/' => $file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
|
||||
$fileurl = moodle_url::make_draftfile_url($newdraftitemid, '/', $filename)->out();
|
||||
header('Location: ' . $fileurl);
|
||||
} else {
|
||||
print_error('cannotdownloaddir', 'repository');
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ default:
|
|||
$path = '/' . trim($draftpath, '/') . '/';
|
||||
$parts = explode('/', $path);
|
||||
foreach ($parts as $part) {
|
||||
if (!empty($part)) {
|
||||
if ($part != '') {
|
||||
$trail .= ('/'.$part.'/');
|
||||
$data->path[] = array('name'=>$part, 'path'=>$trail);
|
||||
$home_url->param('draftpath', $trail);
|
||||
|
@ -297,8 +297,10 @@ default:
|
|||
$home_url->param('action', 'mkdirform');
|
||||
echo ' <a href="'.$home_url->out().'">'.get_string('makeafolder', 'moodle').'</a>';
|
||||
}
|
||||
$home_url->param('action', 'downloaddir');
|
||||
echo html_writer::link($home_url, get_string('downloadfolder', 'repository'), array('target'=>'_blank'));
|
||||
if (!empty($files->list)) {
|
||||
$home_url->param('action', 'downloaddir');
|
||||
echo ' ' . html_writer::link($home_url, get_string('downloadfolder', 'repository'), array('target'=>'_blank'));
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue