diff --git a/badges/badge.php b/badges/badge.php index 29f8cb43c0c..68cf109cb4f 100644 --- a/badges/badge.php +++ b/badges/badge.php @@ -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)); diff --git a/badges/mybadges.php b/badges/mybadges.php index 3f15a93a8e3..a1454dab59b 100644 --- a/badges/mybadges.php +++ b/badges/mybadges.php @@ -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); diff --git a/lib/badgeslib.php b/lib/badgeslib.php index e3729a26ca3..80b57cee9a7 100644 --- a/lib/badgeslib.php +++ b/lib/badgeslib.php @@ -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; } }