当前位置: 首页>>代码示例>>PHP>>正文


PHP moodleform::save_temp_file方法代码示例

本文整理汇总了PHP中moodleform::save_temp_file方法的典型用法代码示例。如果您正苦于以下问题:PHP moodleform::save_temp_file方法的具体用法?PHP moodleform::save_temp_file怎么用?PHP moodleform::save_temp_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在moodleform的用法示例。


在下文中一共展示了moodleform::save_temp_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: useredit_update_picture

/**
 * Updates the provided users profile picture based upon the expected fields
 * returned from the edit or edit_advanced forms.
 *
 * @global moodle_database $DB
 * @param stdClass $usernew An object that contains some information about the user being updated
 * @param moodleform $userform The form that was submitted to edit the form
 * @return bool True if the user was updated, false if it stayed the same.
 */
function useredit_update_picture(stdClass $usernew, moodleform $userform)
{
    global $CFG, $DB;
    require_once "{$CFG->libdir}/gdlib.php";
    $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
    $user = $DB->get_record('user', array('id' => $usernew->id), 'id, picture', MUST_EXIST);
    $newpicture = $user->picture;
    if (!empty($usernew->deletepicture)) {
        // The user has chosen to delete the selected users picture
        $fs = get_file_storage();
        $fs->delete_area_files($context->id, 'user', 'icon');
        // drop all images in area
        $newpicture = 0;
    } else {
        if ($iconfile = $userform->save_temp_file('imagefile')) {
            // There is a new image that has been uploaded
            // Process the new image and set the user to make use of it.
            // NOTE: Uploaded images always take over Gravatar
            $newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile);
            // Delete the file that has now been processed
            @unlink($iconfile);
        }
    }
    if ($newpicture != $user->picture) {
        $DB->set_field('user', 'picture', $newpicture, array('id' => $user->id));
        return true;
    } else {
        return false;
    }
}
开发者ID:nmicha,项目名称:moodle,代码行数:39,代码来源:editlib.php

示例2: useredit_update_picture

/**
 * Updates the provided users profile picture based upon the expected fields
 * returned from the edit or edit_advanced forms.
 *
 * @global moodle_database $DB
 * @param stdClass $usernew An object that contains some information about the user being updated
 * @param moodleform $userform The form that was submitted to edit the form
 * @return bool True if the user was updated, false if it stayed the same.
 */
function useredit_update_picture(stdClass $usernew, moodleform $userform) {
    global $CFG, $DB;
    require_once("$CFG->libdir/gdlib.php");

    $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
    // This will hold the value to set to the user's picture field at the end of
    // this function
    $picturetouse = null;
    if (!empty($usernew->deletepicture)) {
        // The user has chosen to delete the selected users picture
        $fs = get_file_storage();
        $fs->delete_area_files($context->id, 'user', 'icon'); // drop all areas
        $picturetouse = 0;
    } else if ($iconfile = $userform->save_temp_file('imagefile')) {
        // There is a new image that has been uploaded
        // Process the new image and set the user to make use of it.
        // NOTE: This may be overridden by Gravatar
        if (process_new_icon($context, 'user', 'icon', 0, $iconfile)) {
            $picturetouse = 1;
        }
        // Delete the file that has now been processed
        @unlink($iconfile);
    }

    // If we have a picture to set we can now do so. Note this will still be NULL
    // unless the user has changed their picture or caused a change by selecting
    // to delete their picture or use gravatar
    if (!is_null($picturetouse)) {
        $DB->set_field('user', 'picture', $picturetouse, array('id' => $usernew->id));
        return true;
    }

    return false;
}
开发者ID:nigeldaley,项目名称:moodle,代码行数:43,代码来源:editlib.php


注:本文中的moodleform::save_temp_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。