MDL-47085 badges: Fix badges file download issues
Signed-off-by: Yuliya Bozhko <[email protected]>
This commit is contained in:
+5
-6
@@ -26,6 +26,7 @@
|
||||
|
||||
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$id = required_param('hash', PARAM_ALPHANUM);
|
||||
$bake = optional_param('bake', 0, PARAM_BOOL);
|
||||
@@ -37,12 +38,10 @@ $badge = new issued_badge($id);
|
||||
|
||||
if ($bake && ($badge->recipient->id == $USER->id)) {
|
||||
$name = str_replace(' ', '_', $badge->badgeclass['name']) . '.png';
|
||||
ob_start();
|
||||
$file = badges_bake($id, $badge->badgeid);
|
||||
header('Content-Type: image/png');
|
||||
header('Content-Disposition: attachment; filename="'. $name .'"');
|
||||
readfile($file);
|
||||
ob_flush();
|
||||
$filehash = badges_bake($id, $badge->badgeid, $USER->id, true);
|
||||
$fs = get_file_storage();
|
||||
$file = $fs->get_file_by_hash($filehash);
|
||||
send_stored_file($file, 0, 0, true, array('filename' => $name));
|
||||
}
|
||||
|
||||
$PAGE->set_url('/badges/badge.php', array('hash' => $id));
|
||||
|
||||
+5
-8
@@ -26,6 +26,7 @@
|
||||
|
||||
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$search = optional_param('search', '', PARAM_CLEAN);
|
||||
@@ -71,17 +72,13 @@ if ($hide) {
|
||||
require_sesskey();
|
||||
$badge = new badge($download);
|
||||
$name = str_replace(' ', '_', $badge->name) . '.png';
|
||||
ob_start();
|
||||
$file = badges_bake($hash, $download);
|
||||
header('Content-Type: image/png');
|
||||
header('Content-Disposition: attachment; filename="'. $name .'"');
|
||||
readfile($file);
|
||||
ob_flush();
|
||||
$filehash = badges_bake($hash, $download, $USER->id, true);
|
||||
$fs = get_file_storage();
|
||||
$file = $fs->get_file_by_hash($filehash);
|
||||
send_stored_file($file, 0, 0, true, array('filename' => $name));
|
||||
} else if ($downloadall) {
|
||||
require_sesskey();
|
||||
ob_start();
|
||||
badges_download($USER->id);
|
||||
ob_flush();
|
||||
}
|
||||
|
||||
$context = context_user::instance($USER->id);
|
||||
|
||||
+2
-1
@@ -1126,7 +1126,8 @@ function badges_download($userid) {
|
||||
if ($zipper->archive_to_pathname($filelist, $tempzip)) {
|
||||
send_temp_file($tempzip, 'badges.zip');
|
||||
} else {
|
||||
debugging("Problems with archiving the files.");
|
||||
debugging("Problems with archiving the files.", DEBUG_DEVELOPER);
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user