MDL-32639 files: Improved File Manager download and zip support

This commit is contained in:
Frederic Massart 2012-11-06 14:44:56 +08:00
parent 697ade2850
commit 638d72cd0b
6 changed files with 46 additions and 26 deletions

View file

@ -219,7 +219,7 @@ switch ($action) {
$file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, '.');
$parent_path = $file->get_parent_directory()->get_filepath();
$filepath = explode('/', trim($file->get_filepath(), '/'));
$filepath = array_pop($filepath);
@ -237,19 +237,18 @@ switch ($action) {
$zipper = get_file_packer('application/zip');
$fs = get_file_storage();
$area = file_get_draft_area_info($draftid);
if ($area['filecount'] == 0) {
$area = file_get_draft_area_info($draftid, $filepath);
if ($area['filecount'] == 0 && $area['foldercount'] == 0) {
echo json_encode(false);
die;
}
$stored_file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, '.');
if ($filepath === '/') {
$parent_path = '/';
$filename = get_string('files').'.zip';
} else {
$parent_path = $stored_file->get_parent_directory()->get_filepath();
$filename = trim($filepath, '/').'.zip';
$filename = explode('/', trim($filepath, '/'));
$filename = array_pop($filename) . '.zip';
}
// archive compressed file to an unused draft area
@ -257,7 +256,7 @@ switch ($action) {
if ($newfile = $zipper->archive_to_storage(array('/' => $stored_file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
$return = new stdClass();
$return->fileurl = moodle_url::make_draftfile_url($newdraftitemid, '/', $filename)->out();
$return->filepath = $parent_path;
$return->filepath = $filepath;
echo json_encode($return);
} else {
echo json_encode(false);