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


PHP upload_manager::process_file_uploads方法代碼示例

本文整理匯總了PHP中upload_manager::process_file_uploads方法的典型用法代碼示例。如果您正苦於以下問題:PHP upload_manager::process_file_uploads方法的具體用法?PHP upload_manager::process_file_uploads怎麽用?PHP upload_manager::process_file_uploads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在upload_manager的用法示例。


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

示例1: moodle_binary_store_file

function moodle_binary_store_file(&$filename, &$id, &$meta, $ext = ".bin")
{
    # READ-Only
    global $_FILES, $CFG, $course, $wiki, $groupid, $userid, $ewiki_title, $cm;
    if (!$wiki->ewikiacceptbinary) {
        print_error('cannotacceptbin', 'wiki');
        return 0;
    }
    $entry = wiki_get_entry($wiki, $course, $userid, $groupid);
    if (!$entry->id) {
        print_error('cannotgetentry', 'wiki');
    }
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager('upload', false, false, $course, false, 0, true, true);
    if ($um->process_file_uploads("{$course->id}/{$CFG->moddata}/wiki/{$wiki->id}/{$entry->id}/{$ewiki_title}")) {
        $filename = '';
        // this to make sure we don't keep processing in the parent function
        if (!$id) {
            $newfilename = $um->get_new_filename();
            $id = EWIKI_IDF_INTERNAL . $newfilename;
        }
        return true;
    }
    print_error('uploaderror', 'wiki', '', $um->print_upload_log(true));
    return false;
}
開發者ID:nicolasconnault,項目名稱:moodle2.0,代碼行數:26,代碼來源:moodle_binary_store.php

示例2: forum_add_attachment

/**
 *
 */
function forum_add_attachment($post, $inputname, &$message)
{
    global $CFG;
    if (!($forum = get_record("forum", "id", $post->forum))) {
        return "";
    }
    if (!($course = get_record("course", "id", $forum->course))) {
        return "";
    }
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager($inputname, true, false, $course, false, $forum->maxbytes, true, true);
    $dir = forum_file_area_name($post);
    if ($um->process_file_uploads($dir)) {
        $message .= $um->get_errors();
        return $um->get_new_filename();
    }
    $message .= $um->get_errors();
    return null;
}
開發者ID:r007,項目名稱:PMoodle,代碼行數:22,代碼來源:lib.php

示例3: dialogue_add_attachment

/**
 * Saves an uploaded Dialogue attachment to the moddata directory
 *  
 * @param   object  $entry
 * @param   string  $inputname
 * @param   string  messages string, passed by reference
 * @return  string  new file name
 */
function dialogue_add_attachment($entry, $inputname, &$message)
{
    global $CFG, $COURSE;
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager($inputname, true, false, $COURSE, false, 0, true, true);
    $dir = dialogue_file_area_name($entry);
    if ($um->process_file_uploads($dir)) {
        $message .= $um->get_errors();
        return $um->get_new_filename();
    }
    $message .= $um->get_errors();
    return null;
}
開發者ID:netspotau,項目名稱:moodle-mod_dialogue,代碼行數:21,代碼來源:lib.php

示例4: array

 function _postprocess(&$resource)
 {
     global $RESOURCE_WINDOW_OPTIONS;
     global $COURSE, $CFG;
     // for file upload patch
     $alloptions = $RESOURCE_WINDOW_OPTIONS;
     if (!empty($resource->forcedownload)) {
         $resource->popup = '';
         $resource->options = 'forcedownload';
     } else {
         if ($resource->windowpopup) {
             $optionlist = array();
             foreach ($alloptions as $option) {
                 $optionlist[] = $option . "=" . $resource->{$option};
                 unset($resource->{$option});
             }
             $resource->popup = implode(',', $optionlist);
             unset($resource->windowpopup);
             $resource->options = '';
         } else {
             if (empty($resource->framepage)) {
                 $resource->options = '';
             } else {
                 switch ($resource->framepage) {
                     case 1:
                         $resource->options = 'frame';
                         break;
                     case 2:
                         $resource->options = 'objectframe';
                         break;
                     default:
                         $resource->options = '';
                         break;
                 }
             }
             unset($resource->framepage);
             $resource->popup = '';
         }
     }
     $optionlist = array();
     for ($i = 0; $i < $this->maxparameters; $i++) {
         $parametername = "parameter{$i}";
         $parsename = "parse{$i}";
         if (!empty($resource->{$parsename}) and $resource->{$parametername} != "-") {
             $optionlist[] = $resource->{$parametername} . "=" . $resource->{$parsename};
         }
         unset($resource->{$parsename});
         unset($resource->{$parametername});
     }
     $resource->alltext = implode(',', $optionlist);
     //	if ($fromform->type == 'fileupload') {
     // upload file to fixed pre-defined "/" folder
     require_once $CFG->dirroot . '/lib/uploadlib.php';
     if (!($basedir = make_upload_directory("{$COURSE->id}"))) {
         error("The site administrator needs to fix the file permissions");
     }
     $wdir = '/';
     $um = new upload_manager('userfile', false, false, $course, false, 0);
     $dir = "{$basedir}{$wdir}";
     if ($um->process_file_uploads($dir)) {
         notify(get_string('uploadedfile'));
     }
     $resource->reference = $um->files["userfile"]["name"];
     // end of upload code
     //	}
 }
開發者ID:hmatulis,項目名稱:RTL-BIDI-Hebrew-Moodle-Plugins,代碼行數:66,代碼來源:resource.class.php

示例5: object

 function update_content($recordid, $value, $name)
 {
     global $CFG;
     if (!($oldcontent = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid))) {
         // Quickly make one now!
         $oldcontent = new object();
         $oldcontent->fieldid = $this->field->id;
         $oldcontent->recordid = $recordid;
         if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
             error('Could not make an empty record!');
         }
     }
     $content = new object();
     $content->id = $oldcontent->id;
     $names = explode('_', $name);
     switch ($names[2]) {
         case 'file':
             // file just uploaded
             #                $course = get_course('course', 'id', $this->data->course);
             $filename = $_FILES[$names[0] . '_' . $names[1]];
             $filename = $filename['name'];
             $dir = $this->data->course . '/' . $CFG->moddata . '/data/' . $this->data->id . '/' . $this->field->id . '/' . $recordid;
             // only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg
             if ($filename) {
                 require_once $CFG->libdir . '/uploadlib.php';
                 // FIX ME: $course not defined here
                 $um = new upload_manager($names[0] . '_' . $names[1], true, false, $this->data->course, false, $this->field->param3);
                 if ($um->process_file_uploads($dir)) {
                     $newfile_name = $um->get_new_filename();
                     $content->content = $newfile_name;
                     update_record('data_content', $content);
                 }
             }
             break;
         case 'filename':
             // only changing alt tag
             $content->content1 = clean_param($value, PARAM_NOTAGS);
             update_record('data_content', $content);
             break;
         default:
             break;
     }
 }
開發者ID:nadavkav,項目名稱:MoodleTAO,代碼行數:43,代碼來源:field.class.php

示例6: notify

 /**
  * Team members should have same files in their  folder.
  */
 function upload_file()
 {
     global $CFG, $USER;
     error_log('upload_file method');
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $offset = optional_param('offset', 0, PARAM_INT);
     $teamid = optional_param('teamid', '', PARAM_INT);
     $returnurl = 'view.php?id=' . $this->cm->id;
     $filecount = $this->count_user_files($USER->id);
     $submission = $this->get_submission($USER->id);
     if (!$this->can_upload_file($submission, $teamid)) {
         $this->view_header(get_string('upload'));
         notify(get_string('uploaderror', 'assignment'));
         print_continue($returnurl);
         $this->view_footer();
         die;
     }
     //team can not be empty
     $members = $this->get_members_from_team($teamid);
     if ($members && is_array($members)) {
         require_once $CFG->dirroot . '/lib/uploadlib.php';
         $currenttime = time();
         $um = new upload_manager('newfile', false, true, $this->course, false, $this->assignment->maxbytes, true);
         $dir = $this->file_area_name($USER->id);
         check_dir_exists($CFG->dataroot . '/' . $dir, true, true);
         error_log('source dir :' . $dir);
         if ($um->process_file_uploads($dir)) {
             //copy this new file  to other members dir
             //update members' assignment_submission records.
             $file = $um->get_new_filename();
             foreach ($members as $member) {
                 //save this file in other team members' file dir.
                 if ($member->student != $USER->id) {
                     //not process the file folder for itself
                     $memberdir = $this->file_area_name($member->student);
                     check_dir_exists($CFG->dataroot . '/' . $memberdir, true, true);
                     error_log('member dir:' . $memberdir);
                     $this->copy_file($USER->id, $file, $CFG->dataroot . '/' . $memberdir);
                 }
                 //update all team members's assignment_submission records.
                 error_log('update member assignment submission');
                 $submission = $this->get_submission($member->student, true);
                 //create new submission if needed
                 $updated = new object();
                 $updated->id = $submission->id;
                 $updated->timemodified = $currenttime;
                 if (update_record('assignment_submissions', $updated)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($member->student);
                     $this->update_grade($submission);
                     if (!$this->drafts_tracked()) {
                         $this->email_teachers($submission);
                     }
                 } else {
                     $new_filename = $um->get_new_filename();
                     $this->view_header(get_string('upload'));
                     notify(get_string('uploadnotregistered', 'assignment', $new_filename));
                     print_continue($returnurl);
                     $this->view_footer();
                     die;
                 }
             }
         } else {
             $this->view_header(get_string('upload'));
             notify('upload process fail');
             print_continue($returnurl);
             $this->view_footer();
         }
         redirect('view.php?id=' . $this->cm->id);
     }
     $this->view_header(get_string('upload'));
     notify(get_string('uploaderror', 'assignment'));
     echo $um->get_errors();
     print_continue($returnurl);
     $this->view_footer();
     die;
 }
開發者ID:hmatulis,項目名稱:RTL-BIDI-Hebrew-Moodle-Plugins,代碼行數:80,代碼來源:assignment.class.php

示例7: error

        if ($item) {
            $template = get_record('assignment_uploadpdf_tmpl', 'id', $item->template);
            if ($template && $template->course == 0 && !$caneditsite) {
                error("No permission to edit site templates");
            }
            delete_records('assignment_uploadpdf_tmplitm', 'id', $itemid);
            $itemid = 0;
        }
    }
} elseif ($uploadpreview) {
    $partdest = $courseid . IMAGE_PATH;
    $fulldest = $CFG->dataroot . '/' . $partdest;
    check_dir_exists($fulldest);
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager('preview', false, false, $course, false, 0, true);
    if ($um->process_file_uploads($partdest)) {
        $fp = $um->get_new_filepath();
        $fn = $um->get_new_filename();
        require_once 'mypdflib.php';
        $pdf = new MyPDFLib();
        $pdf->load_pdf($fp);
        $pdf->set_image_folder($fulldest);
        $imagename = $pdf->get_image(1);
        unlink($fp);
    } else {
        //echo 'No file uploaded';
        //die;
    }
} elseif ($duplicatetemplate) {
    // Should not have access to the 'duplicate' button unless a template is selected
    // but, just in case, we check here (but just do nothing if that is not the case)
開發者ID:hmatulis,項目名稱:RTL-BIDI-Hebrew-Moodle-Plugins,代碼行數:31,代碼來源:edittemplates.php

示例8: navmenu

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/lightboxgallery:addimage', $context);
$galleryurl = $CFG->wwwroot . '/mod/lightboxgallery/view.php?id=' . $cm->id;
$straddimage = get_string('addimage', 'lightboxgallery');
$navigation = build_navigation($straddimage, $cm);
print_header($course->shortname . ': ' . $gallery->name . ': ' . $straddimage, $course->fullname, $navigation, '', '', true, '&nbsp;', navmenu($course, $cm));
$mform = new mod_lightboxgallery_imageadd_form(null, $gallery);
if ($mform->is_cancelled()) {
    redirect($galleryurl);
} else {
    if (($formdata = $mform->get_data()) && confirm_sesskey()) {
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        $handlecollisions = !get_config('lightboxgallery', 'overwritefiles');
        $um = new upload_manager('attachment', false, $handlecollisions, $course);
        $uploaddir = $course->id . '/' . $gallery->folder;
        if ($um->process_file_uploads($uploaddir)) {
            $folder = $CFG->dataroot . '/' . $uploaddir;
            $filename = $um->get_new_filename();
            $messages = array();
            if (lightboxgallery_get_file_extension($filename) == 'zip') {
                $thumb = '<img src="' . $CFG->pixpath . '/f/zip.gif" class="icon" alt="zip" />';
                $before = lightboxgallery_directory_images($folder);
                if (unzip_file($folder . '/' . $filename, $folder, false)) {
                    $messages[] = get_string('zipextracted', 'lightboxgallery', $filename);
                    $after = lightboxgallery_directory_images($folder);
                    if ($newfiles = array_diff($after, $before)) {
                        $resizeoption = 0;
                        if (in_array($gallery->autoresize, array(AUTO_RESIZE_UPLOAD, AUTO_RESIZE_BOTH))) {
                            $resizeoption = $gallery->resize;
                        } else {
                            if (isset($formdata->resize)) {
開發者ID:itziko,項目名稱:Moodle-jQuery-Lightbox-Gallery,代碼行數:31,代碼來源:imageadd.php

示例9: array

 function process_attachment($course = null)
 {
     if (!$course) {
         $course = get_record('course', 'id', $this->courseid);
     }
     $rtn = array();
     $um = new upload_manager('attach', false, true, $course, false, 0, true);
     if ($um->process_file_uploads('temp/block_student_gradeviewer')) {
         $rtn[] = $um->get_new_filename();
         $rtn[] = 'temp/block_student_gradeviewer/' . $um->get_new_filename();
     } else {
         $rtn = array('', '');
     }
     return $rtn;
 }
開發者ID:rrusso,項目名稱:EARS,代碼行數:15,代碼來源:lib.php

示例10: gettext

 function upload_foaf()
 {
     global $data, $CFG;
     $action = optional_param('action');
     if (!empty($action) && $action == "profile:foaf:upload" && logged_on && run("permissions:check", "profile")) {
         require_once $CFG->dirroot . 'lib/uploadlib.php';
         $um = new upload_manager('foaf_file', false, true, 0, true);
         $dir = $CFG->dataroot . 'tmp/foaf/';
         if (!$um->process_file_uploads($dir)) {
             $messages[] = gettext("There was an error uploading the file. Possibly the file was too large, or the upload was interrupted.");
             $messages[] = $um->get_errors();
             return false;
         }
         $file = $um->get_new_filepath();
         $foaf = @GetXMLTreeProfile($file);
         $data['profile:preload'] = array();
         if (isset($foaf['RDF:RDF'][0]['PERSON'][0]) && !isset($foaf['RDF:RDF'][0]['FOAF:PERSON'][0])) {
             $foaf['RDF:RDF'][0]['FOAF:PERSON'][0] = $foaf['RDF:RDF'][0]['PERSON'][0];
         }
         if (isset($foaf['RDF:RDF'][0]['FOAF:PERSON'][0])) {
             $foaf = $foaf['RDF:RDF'][0]['FOAF:PERSON'][0];
             if (!empty($data['foaf:profile']) && sizeof($data['foaf:profile']) > 0) {
                 foreach ($data['foaf:profile'] as $foaf_element) {
                     $profile_value = addslashes($foaf_element[0]);
                     $foaf_name = $foaf_element[1];
                     $individual = $foaf_element[2];
                     $resource = $foaf_element[3];
                     if (isset($foaf[strtoupper($foaf_name)])) {
                         $values = $foaf[strtoupper($foaf_name)];
                         foreach ($values as $value) {
                             $thisvalue = "";
                             if (trim($value['VALUE']) != "") {
                                 $thisvalue = trim($value['VALUE']);
                             } else {
                                 if (isset($value['ATTRIBUTES']['DC:TITLE']) && trim($value['ATTRIBUTES']['DC:TITLE'] != "")) {
                                     $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']);
                                 } else {
                                     if (isset($value['ATTRIBUTES']['RDF:RESOURCE']) && trim($value['ATTRIBUTES']['RDF:RESOURCE'] != "")) {
                                         $thisvalue = trim($value['ATTRIBUTES']['RDF:RESOURCE']);
                                     }
                                 }
                             }
                             if ($thisvalue != "") {
                                 if (!isset($data['profile:preload'][$profile_value])) {
                                     $data['profile:preload'][$profile_value] = $thisvalue;
                                 } else {
                                     $data['profile:preload'][$profile_value] .= ", " . $thisvalue;
                                 }
                             }
                         }
                     }
                 }
             }
             if (!empty($foaf['VCARD:ADR']) && sizeof($foaf['VCARD:ADR']) > 0) {
                 if (!empty($data['vcard:profile:adr']) && sizeof($data['vcard:profile:adr']) > 0) {
                     $foaf = $foaf['VCARD:ADR'][0];
                     foreach ($data['vcard:profile:adr'] as $foaf_element) {
                         $profile_value = addslashes($foaf_element[0]);
                         $foaf_name = $foaf_element[1];
                         $individual = $foaf_element[2];
                         $resource = $foaf_element[3];
                         if (isset($foaf[strtoupper($foaf_name)])) {
                             $values = $foaf[strtoupper($foaf_name)];
                             foreach ($values as $value) {
                                 $thisvalue = "";
                                 if (trim($value['VALUE']) != "") {
                                     $thisvalue = trim($value['VALUE']);
                                 } else {
                                     if (isset($value['ATTRIBUTES']['DC:TITLE']) && trim($value['ATTRIBUTES']['DC:TITLE'] != "")) {
                                         $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']);
                                     } else {
                                         if (isset($value['ATTRIBUTES']['RDF:RESOURCE']) && trim($value['ATTRIBUTES']['RDF:RESOURECE'] != "")) {
                                             $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']);
                                         }
                                     }
                                 }
                                 if ($thisvalue != "") {
                                     if (!isset($data['profile:preload'][$profile_value])) {
                                         $data['profile:preload'][$profile_value] = $thisvalue;
                                     } else {
                                         $data['profile:preload'][$profile_value] .= ", " . $thisvalue;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $messages[] = gettext("Data from your FOAF file has been preloaded. You must click Save at the bottom of the page for the changes to take effect.");
         } else {
             $messages[] = gettext("Error: supplied file did not appear to be a FOAF file.");
         }
     }
     return true;
 }
開發者ID:pzingg,項目名稱:saugus_elgg,代碼行數:95,代碼來源:profile.class.php

示例11: redirect

 function upload_team_responsefile()
 {
     global $CFG;
     $teamid = required_param('teamid', PARAM_INT);
     $userrep = required_param('userrep', PARAM_INT);
     $mode = required_param('mode', PARAM_ALPHA);
     $id = required_param('id', PARAM_INT);
     $teammembers = $this->get_members_from_team($teamid);
     if ($teammembers) {
         $returnurl = "submissions.php?id={$id}&amp;teamid={$teamid}&amp;userrep={$userrep}&amp;mode={$mode}";
         if (data_submitted('nomatch') and $this->can_manage_responsefiles()) {
             //team responses folder dirs
             $teamdir = $this->team_file_area_name($teamid) . '/responses';
             check_dir_exists($CFG->dataroot . '/' . $teamdir, true, true);
             require_once $CFG->dirroot . '/lib/uploadlib.php';
             $um = new upload_manager('newfile', false, true, $this->course, false, 0, true);
             if (!$um->process_file_uploads($teamdir)) {
                 print_error('uploaderror', 'assignment', $returnurl);
             }
         }
         redirect($returnurl);
     }
 }
開發者ID:ruddj,項目名稱:Moodle-2.0-Team-Assignment,代碼行數:23,代碼來源:assignment.class.php

示例12: notify

 function upload_file()
 {
     global $CFG, $USER;
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $offset = optional_param('offset', 0, PARAM_INT);
     $returnurl = 'view.php?id=' . $this->cm->id;
     $status = false;
     // Indicated whether the file was successfully moved or not.
     $form = new backpack_form();
     // Make sure that data was returned from the form.
     if (!($data = $form->get_data())) {
         $data = $form->get_submitted_data();
     }
     $dir = $this->file_area_name($USER->id);
     check_dir_exists($CFG->dataroot . '/' . $dir, true, true);
     // better to create now so that student submissions do not block it later
     $filecount = $this->count_user_files($USER->id);
     $submission = $this->get_submission($USER->id);
     // Ensure that this user can actually submit a file to this assignment or not.
     if (!$this->can_upload_file($submission)) {
         $this->view_header(get_string('upload'));
         notify(get_string('uploaderror', 'assignment'));
         print_continue($returnurl);
         $this->view_footer();
         die;
     }
     //obtain the repository object, if possible
     //(should be obtainable since the config has already been checked)
     $repo = $this->get_repository_object();
     // If a repository file was chosen for upload
     if (!empty($data->alfrescoassignment) && isset($repo) && $repo->verify_setup() && $repo->is_configured()) {
         $file = $data->alfrescoassignment;
         // Get the UUID value from the repo file URL.
         if (preg_match('/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/', $file, $matches) > 0) {
             if (!empty($matches[0])) {
                 $uuid = $matches[0];
                 $info = $repo->get_info($uuid);
                 $status = $repo->copy_local($uuid, $info->title, $CFG->dataroot . '/' . $dir);
             }
         }
         // If a local file was chosen for upload
     } else {
         if (!empty($data->addfile)) {
             require_once $CFG->dirroot . '/lib/uploadlib.php';
             $um = new upload_manager('localassignment', false, true, $this->course, false, $this->assignment->maxbytes, true);
             $status = $um->process_file_uploads($dir);
         }
     }
     if ($status) {
         $submission = $this->get_submission($USER->id, true);
         //create new submission if needed
         $updated = new stdClass();
         $updated->id = $submission->id;
         $updated->timemodified = time();
         if (update_record('assignment_submissions', $updated)) {
             add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
             $submission = $this->get_submission($USER->id);
             $this->update_grade($submission);
             if (!$this->drafts_tracked()) {
                 $this->email_teachers($submission);
             }
         } else {
             $new_filename = $um->get_new_filename();
             $this->view_header(get_string('upload'));
             notify(get_string('uploadnotregistered', 'assignment', $new_filename));
             print_continue($returnurl);
             $this->view_footer();
             die;
         }
         redirect('view.php?id=' . $this->cm->id);
     }
     $this->view_header(get_string('upload'));
     notify(get_string('uploaderror', 'assignment'));
     if (!empty($um)) {
         echo $um->get_errors();
     }
     print_continue($returnurl);
     $this->view_footer();
     die;
 }
開發者ID:remotelearner,項目名稱:elis.alfresco,代碼行數:80,代碼來源:assignment.class.php

示例13: upload

 function upload()
 {
     global $CFG, $USER;
     require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id));
     $this->view_header(get_string('upload'));
     $filecount = $this->count_user_files($USER->id);
     $submission = $this->get_submission($USER->id);
     if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
         if ($submission = $this->get_submission($USER->id)) {
             //TODO: change later to ">= 0", to prevent resubmission when graded 0
             if ($submission->grade > 0 and !$this->assignment->resubmit) {
                 notify(get_string('alreadygraded', 'assignment'));
             }
         }
         $dir = $this->file_area_name($USER->id);
         require_once $CFG->dirroot . '/lib/uploadlib.php';
         $um = new upload_manager('newfile', true, false, $this->course, false, $this->assignment->maxbytes);
         if ($um->process_file_uploads($dir) and confirm_sesskey()) {
             $newfile_name = $um->get_new_filename();
             if ($submission) {
                 $submission->timemodified = time();
                 $submission->numfiles = 1;
                 $submission->submissioncomment = addslashes($submission->submissioncomment);
                 unset($submission->data1);
                 // Don't need to update this.
                 unset($submission->data2);
                 // Don't need to update this.
                 if (update_record("assignment_submissions", $submission)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($submission);
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadfailnoupdate", "assignment"));
                 }
             } else {
                 $newsubmission = $this->prepare_new_submission($USER->id);
                 $newsubmission->timemodified = time();
                 $newsubmission->numfiles = 1;
                 if (insert_record('assignment_submissions', $newsubmission)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($newsubmission);
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadnotregistered", "assignment", $newfile_name));
                 }
             }
         }
     } else {
         notify(get_string("uploaderror", "assignment"));
         //submitting not allowed!
     }
     print_continue('view.php?id=' . $this->cm->id);
     $this->view_footer();
 }
開發者ID:edwinphillips,項目名稱:moodle-485cb39,代碼行數:58,代碼來源:assignment.class.php

示例14: upload

 function upload()
 {
     global $CFG, $USER;
     require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id));
     // $this->view_header(get_string('upload'));
     echo "<center>";
     $filecount = $this->count_user_files($USER->id);
     $submission = $this->get_submission($USER->id);
     if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
         if ($submission = $this->get_submission($USER->id)) {
             //TODO: change later to ">= 0", to prevent resubmission when graded 0
             if ($submission->grade > 0 and !$this->assignment->resubmit) {
                 notify(get_string('alreadygraded', 'assignment'));
             }
         }
         $dir = $this->file_area_name($USER->id);
         require_once $CFG->dirroot . '/lib/uploadlib.php';
         $um = new upload_manager('newfile', true, false, $this->course, false, $this->assignment->maxbytes);
         if ($um->process_file_uploads($dir)) {
             $newfile_name = $um->get_new_filename();
             if ($submission) {
                 $submission->timemodified = time();
                 $submission->numfiles = 1;
                 $submission->submissioncomment = addslashes($submission->submissioncomment);
                 unset($submission->data1);
                 // Don't need to update this.
                 unset($submission->data2);
                 // Don't need to update this.
                 if (update_record("assignment_submissions", $submission)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view-embedded.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($submission);
                     echo "Hands-on exams will be graded within 10 business days. Results will be provided via email. If you do not receive your results within 10 business days of submitting your answer file, please open a ticket with Kaseya University at helpdesk.kaseya.com.";
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadfailnoupdate", "assignment"));
                 }
             } else {
                 $newsubmission = $this->prepare_new_submission($USER->id);
                 $newsubmission->timemodified = time();
                 $newsubmission->numfiles = 1;
                 if (insert_record('assignment_submissions', $newsubmission)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view-embedded.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($newsubmission);
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadnotregistered", "assignment", $newfile_name));
                 }
             }
         }
     } else {
         notify(get_string("uploaderror", "assignment"));
         //submitting not allowed!
     }
     print_continue('view-embedded.php?id=' . $this->cm->id);
     echo "</center>";
     // $this->view_footer();
 }
開發者ID:arshanam,項目名稱:Moodle-ITScholars-LMS,代碼行數:61,代碼來源:assignment_embedded.class.php

示例15: foreach

 /**
  * This function add new files into mailid.
  *
  * @uses $CFG
  * @access protected
  * @version 1.0
  * @param $attachments Is an array get to $_FILES
  * @return string Array of all name attachments upload
  */
 function add_attachments()
 {
     global $CFG;
     /// Note: $attachments is an array, who it's 5 sub-array in here.
     /// name, type, tmp_name. size, error who have an arrays.
     // Prevent errors
     if (empty($this->oldattachments) and (empty($this->attachments) or isset($this->attachments['FILE_0']['error']) and $this->attachments['FILE_0']['error'] == 4)) {
         return true;
     }
     // Get course for upload manager
     if (!($course = get_record('course', 'id', $this->course))) {
         return '';
     }
     require_once $CFG->dirroot . '/lib/uploadlib.php';
     // Get directory for save this attachments
     $dir = $this->get_file_area();
     // Now, delete old corresponding files
     if (!empty($this->oldattachments)) {
         if ($this->type != EMAIL_FORWARD and $this->type != EMAIL_REPLY and $this->type != EMAIL_REPLYALL) {
             // Working in same email
             // Necessary library for this function
             include_once $CFG->dirroot . '/lib/filelib.php';
             // Get files of mail
             if ($files = get_directory_list($dir)) {
                 // Process all attachments
                 foreach ($files as $file) {
                     // Get path of file
                     $attach = $this->get_file_area_name() . '/' . $file;
                     $attachments[] = $attach;
                 }
             }
             if ($diff = array_diff($attachments, $this->oldattachments)) {
                 foreach ($diff as $attachment) {
                     unlink($CFG->dataroot . '/' . $attachment);
                     // Drop file
                 }
             }
         } else {
             if ($this->type === EMAIL_FORWARD) {
                 // Copy $this->oldattachments in this new email
                 foreach ($this->oldattachments as $attachment) {
                     copy($CFG->dataroot . '/' . $attachment, $this->get_file_area() . '/' . basename($attachment));
                 }
             }
         }
     }
     if (!empty($this->attachments) or isset($this->attachments['FILE_0']['error']) and $this->attachments['FILE_0']['error'] != 4) {
         // Now, processing all attachments . . .
         $um = new upload_manager(NULL, false, false, $course, false, 0, true, true);
     }
     if (!$um->process_file_uploads($dir)) {
         // empty file upload. Error solve in latest version of moodle.
         // Warning! Only comprove first mail. Bug of uploadlib.php.
         $message = get_string('uploaderror', 'assignment');
         $message .= '<br />';
         $message .= $um->get_errors();
         print_simple_box($message, '', '', '', '', 'errorbox');
         print_continue($CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id);
         print_footer();
         die;
     }
     return true;
 }
開發者ID:henriquecrang,項目名稱:e-UNI,代碼行數:72,代碼來源:email.class.php


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