當前位置: 首頁>>代碼示例>>PHP>>正文


PHP send_stored_file函數代碼示例

本文整理匯總了PHP中send_stored_file函數的典型用法代碼示例。如果您正苦於以下問題:PHP send_stored_file函數的具體用法?PHP send_stored_file怎麽用?PHP send_stored_file使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了send_stored_file函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: assignfeedback_editpdf_pluginfile

/**
 * Serves assignment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignfeedback_editpdf_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB, $CFG;
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_login($course, false, $cm);
        $itemid = (int) array_shift($args);
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        $record = $DB->get_record('assign_grades', array('id' => $itemid), 'userid,assignment', MUST_EXIST);
        $userid = $record->userid;
        if ($assign->id != $record->assignment) {
            return false;
        }
        // Check is users feedback or has grading permission.
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/assignfeedback_editpdf/{$filearea}/{$itemid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Download MUST be forced - security!
        send_stored_file($file, 0, 0, true);
        // Check if we want to retrieve the stamps.
    }
}
開發者ID:pzhu2004,項目名稱:moodle,代碼行數:40,代碼來源:lib.php

示例2: streamFileContent

 public function streamFileContent()
 {
     if (!$this->fileref) {
         $this->fileref = $this->getFile();
     }
     \send_stored_file($this->fileref);
 }
開發者ID:phish108,項目名稱:PowerTLA,代碼行數:7,代碼來源:File.class.php

示例3: block_jmail_pluginfile

/**
 * Serves the message attachments. Implements needed access control ;-)
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function block_jmail_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        //send_file_not_found();
    }
    require_course_login($course);
    $coursecontext = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST);
    // The mailbox constructor does the permission validation
    if (!($mailbox = new block_jmail_mailbox($course, $coursecontext, $context))) {
        return;
    }
    $messageid = (int) array_shift($args);
    $message = block_jmail_message::get_from_id($messageid);
    // We check if we are the senders or the receivers
    if (!$message) {
        send_file_not_found();
    }
    $pendingaprobal = !$message->approved and has_capability('block/jmail:approvemessages', $context);
    if (!$message->is_mine() and !$pendingaprobal) {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/block_jmail/{$filearea}/{$messageid}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    $forcedownload = true;
    send_stored_file($file, 60 * 60, 0, $forcedownload);
}
開發者ID:borrown,項目名稱:moodle-block_jmail,代碼行數:42,代碼來源:lib.php

示例4: workshopform_numerrors_pluginfile

function workshopform_numerrors_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) {
    global $DB;

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_login($course, true, $cm);

    if ($filearea !== 'description') {
        return false;
    }

    $itemid = (int)array_shift($args); // the id of the assessment form dimension
    if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
        send_file_not_found();
    }

    if (!$dimension = $DB->get_record('workshopform_numerrors', array('id' => $itemid ,'workshopid' => $workshop->id))) {
        send_file_not_found();
    }

    // TODO now make sure the user is allowed to see the file
    // (media embedded into the dimension description)

    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/$context->id/workshopform_numerrors/$filearea/$itemid/$relativepath";
    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
        return false;
    }

    // finally send the file
    send_stored_file($file);
}
開發者ID:nuckey,項目名稱:moodle,代碼行數:35,代碼來源:lib.php

示例5: assignsubmission_onenote_pluginfile

/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onenote_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $assign = new assign($context, $cm, $course);
    if ($assign->get_instance()->id != $record->assignment) {
        return false;
    }
    if ($assign->get_instance()->teamsubmission && !$assign->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$assign->get_instance()->teamsubmission && !$assign->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onenote/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
開發者ID:eugeneventer,項目名稱:o365-moodle,代碼行數:42,代碼來源:lib.php

示例6: local_filemanager_pluginfile

function local_filemanager_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB;
    if ($context->contextlevel != CONTEXT_SYSTEM) {
        return false;
    }
    require_login();
    if ($filearea != 'attachment') {
        return false;
    }
    $itemid = (int) array_shift($args);
    if ($itemid != 0) {
        return false;
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    if (empty($args)) {
        $filepath = '/';
    } else {
        $filepath = '/' . implode('/', $args) . '/';
    }
    $file = $fs->get_file($context->id, 'local_filemanager', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
    }
    // finally send the file
    send_stored_file($file, 0, 0, true, $options);
    // download MUST be forced - security!
}
開發者ID:sharkadder,項目名稱:filemanager-1,代碼行數:29,代碼來源:lib.php

示例7: dataformview_tabular_pluginfile

/**
 * Serves the dataformview_tabular template files.
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function dataformview_tabular_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    if (!in_array($filearea, dataformview_tabular_tabular::get_file_areas())) {
        return false;
    }
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_course_login($course, true, $cm);
        $viewid = (int) array_shift($args);
        $dataformid = $cm->instance;
        // Confirm user access.
        $params = array('dataformid' => $dataformid, 'viewid' => $viewid);
        if (!mod_dataform\access\view_access::validate($params)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/dataformview_tabular/{$filearea}/{$viewid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Finally send the file.
        send_stored_file($file, 0, 0, true);
        // Download MUST be forced - security!
    }
    return false;
}
開發者ID:parksandwildlife,項目名稱:learning,代碼行數:37,代碼來源:lib.php

示例8: atto_ejsapp_pluginfile

function atto_ejsapp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    // Make sure the user is logged in and has access to the module (plugins that are not course modules should leave out the 'cm' part).
    require_login($course, true, $cm);
    // Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
    $itemid = array_shift($args);
    // The first item in the $args array.
    // Use the itemid to retrieve any relevant data records and perform any security checks to see if the
    // user really does have access to the file in question.
    // Extract the filename / filepath from the $args array.
    $filename = array_pop($args);
    // The last item in the $args array.
    if (!$args) {
        $filepath = '/';
        // $args is empty => the path is '/'
    } else {
        $filepath = '/' . implode('/', $args) . '/';
        // $args contains elements of the filepath
    }
    // Retrieve the file from the Files API.
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'atto_ejsapp', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
        // The file does not exist.
    }
    // We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
    // From Moodle 2.3, use send_stored_file instead.
    send_stored_file($file, 86400, 0, $forcedownload, $options);
}
開發者ID:UNEDLabs,項目名稱:moodle-atto_ejsapp,代碼行數:30,代碼來源:lib.php

示例9: block_html_pluginfile

/**
 * Form for editing HTML block instances.
 *
 * @copyright 2010 Petr Skoda (http://skodak.org)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_html
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    require_course_login($course);
    if ($filearea !== 'content') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
開發者ID:nmicha,項目名稱:moodle,代碼行數:45,代碼來源:lib.php

示例10: seplfeedback_file_pluginfile

/**
 * Serves seplment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function seplfeedback_file_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('sepl_grades', array('id' => $itemid), 'userid,seplment', MUST_EXIST);
    $userid = $record->userid;
    if (!($sepl = $DB->get_record('sepl', array('id' => $cm->instance)))) {
        return false;
    }
    if ($sepl->id != $record->seplment) {
        return false;
    }
    // Check is users feedback or has grading permission.
    if ($USER->id != $userid and !has_capability('mod/sepl:grade', $context)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/seplfeedback_file/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
開發者ID:krzpassrl,項目名稱:SRL_Moodle_Baseline,代碼行數:40,代碼來源:lib.php

示例11: teamworkform_rubric_pluginfile

/**
 * Server teamwork files
 *
 * @category files
 * @param stdClass $course course object
 * @param stdClass $cm course module object
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function teamworkform_rubric_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options = array())
{
    global $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, true, $cm);
    if ($filearea !== 'description') {
        return false;
    }
    $itemid = (int) array_shift($args);
    // the id of the assessment form dimension
    if (!($teamwork = $DB->get_record('teamwork', array('id' => $cm->instance)))) {
        send_file_not_found();
    }
    if (!($dimension = $DB->get_record('teamworkform_rubric', array('id' => $itemid, 'teamworkid' => $teamwork->id)))) {
        send_file_not_found();
    }
    // TODO now make sure the user is allowed to see the file
    // (media embedded into the dimension description)
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/teamworkform_rubric/{$filearea}/{$itemid}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    // finally send the file
    send_stored_file($file, 0, 0, $forcedownload, $options);
}
開發者ID:Gavinthisisit,項目名稱:Moodle,代碼行數:42,代碼來源:lib.php

示例12: block_testimonials_pluginfile

/**
 * Testimonials block for Moodle
 *
 * @package   block_testimonials
 * @copyright 2015 Thomas Threadgold <tj.threadgold@gmail.com>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function block_testimonials_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        return false;
    }
    if ($filearea !== 'photo') {
        return false;
    }
    $itemid = array_shift($args);
    // Extract the filename / filepath from the $args array.
    $filename = array_pop($args);
    // The last item in the $args array.
    if (!$args) {
        $filepath = '/';
        // $args is empty => the path is '/'
    } else {
        $filepath = '/' . implode('/', $args) . '/';
        // $args contains elements of the filepath
    }
    // Retrieve the file from the Files API.
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'block_testimonials', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
        // The file does not exist.
    }
    send_stored_file($file, 86400, 0, $forcedownload, $options);
}
開發者ID:Regaez,項目名稱:moodle-block_testimonials,代碼行數:36,代碼來源:lib.php

示例13: assignsubmission_onlinepoodll_pluginfile

/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onlinepoodll_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    //back image is a special case
    if (!($itemid == 0 && ($filearea = "onlinepoodll_backimage"))) {
        $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment', MUST_EXIST);
        $userid = $record->userid;
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        if ($assign->id != $record->assignment) {
            return false;
        }
        // check is users submission or has grading permission
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onlinepoodll/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file, 0, 0, true);
    // download MUST be forced - security!
}
開發者ID:laiello,項目名稱:poodll.poodll23,代碼行數:43,代碼來源:lib.php

示例14: block_xp_pluginfile

/**
 * File serving.
 *
 * @param stdClass $course The course object.
 * @param stdClass $bi Block instance record.
 * @param context $context The context object.
 * @param string $filearea The file area.
 * @param array $args List of arguments.
 * @param bool $forcedownload Whether or not to force the download of the file.
 * @param array $options Array of options.
 * @return void|false
 */
function block_xp_pluginfile($course, $bi, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if ($CFG->block_xp_context == CONTEXT_SYSTEM && $context->contextlevel !== CONTEXT_SYSTEM) {
        return false;
    } else {
        if ($CFG->block_xp_context != CONTEXT_SYSTEM && $context->contextlevel !== CONTEXT_COURSE) {
            return false;
        }
    }
    $fs = get_file_storage();
    $file = null;
    if ($filearea == 'badges') {
        // For performance reason, and very low risk, we do not restrict the access to the level badges
        // to the participant of the course, nor do we check if they have the required level, etc...
        $itemid = array_shift($args);
        $filename = array_shift($args);
        $filepath = '/';
        $file = $fs->get_file($context->id, 'block_xp', $filearea, $itemid, $filepath, $filename . '.png');
        if (!$file) {
            $file = $fs->get_file($context->id, 'block_xp', $filearea, $itemid, $filepath, $filename . '.jpg');
        }
    }
    if (!$file) {
        return false;
    }
    send_stored_file($file);
}
開發者ID:antoniorodrigues,項目名稱:redes-digitais,代碼行數:40,代碼來源:lib.php

示例15: block_eexcess_pluginfile

/**
 * Serves the eexcess files.
 *
 * @param stdClass $course course object
 * @param stdClass $cm course module object
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @return bool false if file not found, does not return if found - just send the file
 */
function block_eexcess_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    $fullpath = "/{$context->id}/block_eexcess/{$filearea}/{$args[0]}/{$args[1]}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file);
}
開發者ID:EEXCESS,項目名稱:moodle-block_eexcess,代碼行數:20,代碼來源:lib.php


注:本文中的send_stored_file函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。