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


PHP upload_manager::save_files方法代码示例

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


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

示例1:

 /**
  * Save verified uploaded files into directory. Upload process can be customised from definition()
  * method by creating instance of upload manager and storing it in $this->_upload_form
  *
  * @param string $destination where to store uploaded files
  * @return bool success
  */
 function save_files($destination)
 {
     if ($this->is_submitted() and $this->is_validated()) {
         return $this->_upload_manager->save_files($destination);
     }
     return false;
 }
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:14,代码来源:formslib.php

示例2: upload_response

/**
 * Uploads the file submitted (adapted from mod/workshop/submissions.php)
 *
 * @param string $fileid string corresponding to the input file ('resp##_file')
 * @param int $attemptid attempt id
 * @param int $questionid question id
 * @param int $maxbytes maximum upload size in bytes
 * @return string feedback from upload, related to success or failure
 */
function upload_response($fileid, $course, $attemptid, $questionid, $maxbytes)
{
    global $CFG;
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager($fileid, true, false, $course, true, $maxbytes, true);
    if ($um->preprocess_files()) {
        $dir = quiz_file_area_name($attemptid, $questionid);
        if (!quiz_file_area($dir)) {
            return get_string('uploadproblem');
        }
        if ($um->save_files($dir)) {
            return get_string('uploadedfile');
        }
    }
    return get_string('uploaderror', 'qtype_fileresponse');
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:25,代码来源:locallib.php

示例3: wiki_upload_file

function wiki_upload_file($file, &$WS)
{
    global $_FILES;
    if (file_exists($WS->dfdir->name . '/' . $_FILES[$file]['name'])) {
        //file already existst in the server
        $WS->dfdir->error[] = get_string('fileexisterror', 'wiki');
    } else {
        //save file
        $upd = new upload_manager('dfformfile');
        $upd->preprocess_files();
        if (!$upd->save_files($WS->dfdir->name)) {
            //error uploading
            $WS->dfdir->error[] = get_string('fileuploaderror', 'wiki');
        }
    }
    $WS->dfdir->content = get_directory_list($WS->dfdir->name);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:17,代码来源:uploadlib.php

示例4: turnitintool_dofileupload_pre_29


//.........这里部分代码省略.........
    if (empty($submissiontitle)) {
        $notice["error"] .= get_string('submissiontitleerror', 'turnitintool') . '<br />';
        $error = true;
    }
    if (!isset($post['agreement'])) {
        $notice["error"] .= get_string('submissionagreementerror', 'turnitintool') . '<br />';
        $error = true;
    }
    $checksubmission = turnitintool_checkforsubmission($cm, $turnitintool, $post['submissionpart'], $userid);
    if (!$error and isset($checksubmission->id) and $turnitintool->reportgenspeed == 0) {
        // Kill the script here as we do not want double errors
        // We only get here if there are no other errors
        turnitintool_print_error('alreadysubmitted', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
        exit;
    }
    $resubmission = false;
    if (isset($checksubmission->id) and $turnitintool->reportgenspeed > 0) {
        $resubmission = true;
    }
    if ($resubmission and $checksubmission->dtdue < time()) {
        turnitintool_print_error('alreadysubmitted', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
        exit;
    }
    $explode = explode('.', $_FILES['submissionfile']['name']);
    $extension = array_pop($explode);
    $_FILES['submissionfile']['name'] = $post['submissionpart'] . '_' . time() . '_' . $userid . '.' . $extension;
    $upload = new upload_manager();
    if (!$upload->preprocess_files()) {
        $notice["error"] .= $upload->notify;
        $error = true;
    }
    if (!$error) {
        $submitobject = new stdClass();
        $submitobject->userid = $userid;
        $submitobject->turnitintoolid = $turnitintool->id;
        $submitobject->submission_part = $post['submissionpart'];
        $submitobject->submission_type = $post['submissiontype'];
        $submitobject->submission_filename = $_FILES['submissionfile']['name'];
        $submitobject->submission_queued = null;
        $submitobject->submission_attempts = 0;
        $submitobject->submission_gmimaged = 0;
        $submitobject->submission_status = null;
        $submitobject->submission_modified = time();
        $submitobject->submission_objectid = !isset($checksubmission->submission_objectid) ? null : $checksubmission->submission_objectid;
        if (!isset($checksubmission->submission_unanon) or $checksubmission->submission_unanon) {
            // If non anon resubmission or new submission set the title as what was entered in the form
            $submitobject->submission_title = $submissiontitle;
            if (!$turnitintool->anon) {
                // If not anon assignment and this is a non anon resubmission or a new submission set the unanon flag to true (1)
                $submitobject->submission_unanon = 1;
            }
        }
        if (!$resubmission) {
            // Prevent duplication in issues where the TII servers may be inaccessible.
            if (!($check_existing = turnitintool_get_records_select('turnitintool_submissions', 'userid=' . $submitobject->userid . ' AND turnitintoolid=' . $submitobject->turnitintoolid . ' AND submission_part=' . $submitobject->submission_part))) {
                if (!($submitobject->id = turnitintool_insert_record('turnitintool_submissions', $submitobject))) {
                    turnitintool_print_error('submissioninserterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                    exit;
                }
            }
        } else {
            $submitobject->id = $checksubmission->id;
            $submitobject->submission_score = null;
            $submitobject->submission_grade = null;
            if (!turnitintool_update_record('turnitintool_submissions', $submitobject)) {
                turnitintool_print_error('submissionupdateerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                exit;
            } else {
                $submitobject->id = $checksubmission->id;
            }
        }
        if (is_callable("get_file_storage")) {
            $fs = get_file_storage();
            $file_record = array('contextid' => $cm->id, 'component' => 'mod_turnitintool', 'filearea' => 'submission', 'itemid' => $submitobject->id, 'filepath' => '/', 'filename' => $submitobject->submission_filename, 'userid' => $submitobject->userid);
            if (!$fs->create_file_from_pathname($file_record, $_FILES['submissionfile']['tmp_name'])) {
                turnitintool_delete_records('turnitintool_submissions', 'id', $submitobject->id);
                turnitintool_print_error('fileuploaderror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                exit;
            }
        } else {
            $destination = turnitintool_file_path($cm, $turnitintool, $userid);
            if (!$upload->save_files($destination)) {
                turnitintool_delete_records('turnitintool_submissions', 'id', $submitobject->id);
                turnitintool_print_error('fileuploaderror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                exit;
            }
        }
        if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id)) and !$turnitintool->autosubmission) {
            turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions');
            exit;
        } else {
            if (!$turnitintool->autosubmission) {
                turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=' . $param_do);
                exit;
            }
        }
        $notice["subid"] = $submitobject->id;
    }
    return $notice;
}
开发者ID:ccle,项目名称:moodle-mod_turnitintool,代码行数:101,代码来源:lib.php

示例5:

                    $newassessment = workshop_copy_assessment($assessment, $newsubmission, true);
                    // set the resubmission flag so student can be emailed/told about
                    // this assessment
                    set_field("workshop_assessments", "resubmission", 1, "id", $newassessment->id);
                }
            } else {
                // a hot assessment, was not used, just dump it
                delete_records("workshop_assessments", "id", $assessment->id);
            }
        }
    }
    add_to_log($course->id, "workshop", "resubmit", "view.php?id={$cm->id}", "{$workshop->id}", "{$cm->id}");
}
// do something about the attachments, if there are any
if ($workshop->nattachments) {
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager(null, false, false, $course, false, $workshop->maxbytes);
    if ($um->preprocess_files()) {
        $dir = workshop_file_area_name($workshop, $newsubmission);
        if ($um->save_files($dir)) {
            print_heading(get_string("uploadsuccess", "workshop"));
        }
        // um will take care of printing errors.
    }
}
if (!$workshop->nattachments) {
    print_heading(get_string("submitted", "workshop") . " " . get_string("ok"));
}
add_to_log($course->id, "workshop", "submit", "view.php?id={$cm->id}", "{$workshop->id}", "{$cm->id}");
print_continue("view.php?id={$cm->id}");
print_footer($course);
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:31,代码来源:upload.php

示例6: upload

 function upload()
 {
     global $CFG, $USER;
     $NUM_REVIEWS = 2;
     $POOL_SIZE = 2 * $NUM_REVIEWS + 1;
     // including current submitter
     require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id));
     $this->view_header(get_string('upload'));
     if ($this->isopen()) {
         if (!record_exists('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $USER->id)) {
             $newsubmission = NULL;
             // Process online text
             if (isset($this->assignment->var3) && $this->assignment->var3 == self::ONLINE_TEXT) {
                 $newsubmission = $this->prepare_new_submission($USER->id);
                 $newsubmission->data1 = addslashes(required_param('text', PARAM_CLEANHTML));
                 $sumbissionName = get_string('yoursubmission', 'assignment_peerreview');
                 // echo '<pre>'.print_r($_POST,true).'</pre>';
             } else {
                 $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->preprocess_files()) {
                     //Check the file extension
                     $submittedFilename = $um->get_original_filename();
                     $extension = $this->assignment->fileextension;
                     if (strtolower(substr($submittedFilename, strlen($submittedFilename) - strlen($extension))) != $extension) {
                         notify(get_string("incorrectfileextension", "assignment_peerreview", $extension));
                     } else {
                         if ($um->save_files($dir)) {
                             $sumbissionName = $um->get_new_filename();
                             $newsubmission = $this->prepare_new_submission($USER->id);
                             $newsubmission->numfiles = 1;
                         }
                     }
                 }
             }
             if ($newsubmission) {
                 // Enter submission into DB and log
                 $newsubmission->timecreated = time();
                 $newsubmission->timemodified = time();
                 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);
                     // $this->email_teachers($newsubmission);
                     print_heading(get_string('uploadedfile'));
                     $submissionSuccess = true;
                 } else {
                     notify(get_string("uploadnotregistered", "assignment", $sumbissionName));
                 }
                 // Allocate reviews
                 $recentSubmissions = array();
                 $numberOfRecentSubmissions = 0;
                 if ($submissionResult = get_records_sql('SELECT userid FROM ' . $CFG->prefix . 'assignment_submissions WHERE assignment=\'' . $this->assignment->id . '\' ORDER BY timecreated DESC, id DESC', 0, $POOL_SIZE + 1)) {
                     $recentSubmissions = array_values($submissionResult);
                     $numberOfRecentSubmissions = count($recentSubmissions);
                 }
                 if ($numberOfRecentSubmissions >= $POOL_SIZE) {
                     for ($i = 2; $i < 2 * $NUM_REVIEWS + 1; $i += 2) {
                         if (!insert_record('assignment_review', $this->prepare_new_review($USER->id, $recentSubmissions[$i]->userid))) {
                             notify(get_string("reviewsallocationerror", "assignment_peerreview"));
                         }
                     }
                 }
                 // If pool just got large enough, allocated reviews to previous submitters
                 if ($numberOfRecentSubmissions == $POOL_SIZE) {
                     $recentSubmissions = array_reverse($recentSubmissions);
                     for ($i = 0; $i < $POOL_SIZE - 1; $i++) {
                         for ($j = 1; $j <= $NUM_REVIEWS; $j++) {
                             insert_record('assignment_review', $this->prepare_new_review($recentSubmissions[$i]->userid, $recentSubmissions[$i - 2 * $j + ($i - 2 * $j >= 0 ? 0 : $NUM_REVIEWS * 2 + 1)]->userid));
                         }
                         // Send an email to student
                         $subject = get_string('reviewsallocatedsubject', 'assignment_peerreview');
                         $linkToReview = $CFG->wwwroot . '/mod/assignment/view.php?id=' . $this->cm->id;
                         $message = get_string('reviewsallocated', 'assignment_peerreview') . "\n\n" . get_string('assignmentname', 'assignment') . ': ' . $this->assignment->name . "\n" . get_string('course') . ': ' . $this->course->fullname . "\n\n";
                         $messageText = $message . $linkToReview;
                         $messageHTML = nl2br($message) . '<a href="' . $linkToReview . '" target="_blank">' . get_string('reviewsallocatedlinktext', 'assignment_peerreview') . '</a>';
                         $this->email_from_teacher($this->course->id, $recentSubmissions[$i]->userid, $subject, $messageText, $messageHTML);
                     }
                 }
                 if ($numberOfRecentSubmissions >= $POOL_SIZE) {
                     redirect('view.php?id=' . $this->cm->id, get_string("reviewsallocated", "assignment_peerreview"), 2);
                 } else {
                     notify(get_string("poolnotlargeenough", "assignment_peerreview"), 'notifysuccess');
                     print_continue('view.php?id=' . $this->cm->id);
                 }
             }
         } else {
             notify(get_string("resubmit", "assignment_peerreview", $this->course->teacher));
             // re-submitting not allowed
             print_continue('view.php?id=' . $this->cm->id);
         }
     } else {
         notify(get_string("closed", "assignment_peerreview"));
         // assignment closed
         print_continue('view.php?id=' . $this->cm->id);
     }
     $this->view_footer();
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:97,代码来源:assignment.class.php

示例7: tracker_recordelements

/**
* stores in database the element values
* @uses $CFG
* @param object $issue
*/
function tracker_recordelements(&$issue)
{
    global $CFG, $COURSE;
    $keys = array_keys($_POST);
    // get the key value of all the fields submitted
    $keys = preg_grep('/element./', $keys);
    // filter out only the element keys
    $filekeys = array_keys($_FILES);
    // get the key value of all the fields submitted
    $filekeys = preg_grep('/element./', $filekeys);
    // filter out only the element keys
    $keys = array_merge($keys, $filekeys);
    foreach ($keys as $key) {
        preg_match('/element(.*)$/', $key, $elementid);
        $elementname = $elementid[1];
        $sql = "\n            SELECT \n              e.id as elementid,\n              e.type as type\n            FROM\n                {$CFG->prefix}tracker_elementused eu,\n                {$CFG->prefix}tracker_element e\n            WHERE\n                eu.elementid = e.id AND\n                e.name = '{$elementname}' AND\n                eu.trackerid = {$issue->trackerid} \n        ";
        $attribute = get_record_sql($sql);
        $attribute->timemodified = $issue->datereported;
        $values = optional_param($key, '', PARAM_CLEANHTML);
        $attribute->issueid = $issue->id;
        $attribute->trackerid = $issue->trackerid;
        /// For those elements where more than one option can be selected
        if (is_array($values)) {
            foreach ($values as $value) {
                $attribute->elementitemid = $value;
                $attributeid = insert_record('tracker_issueattribute', $attribute);
                if (!$attributeid) {
                    error("Could not submit issue(s) attribute(s): issue:{$issue->id} issueid:{$elementid['1']} elementitemid:{$attribute->elementitemid}");
                }
            }
        } else {
            //For the rest of the elements that can only support one answer
            if ($attribute->type != 'file') {
                require_once $CFG->libdir . '/uploadlib.php';
                $attribute->elementitemid = $values;
                $attributeid = insert_record('tracker_issueattribute', $attribute);
            } else {
                $uploader = new upload_manager($key, false, false, $COURSE->id, true, 0, true);
                $uploader->preprocess_files();
                $newfilename = $uploader->get_new_filename();
                $encodedfilename = '';
                if (!empty($newfilename)) {
                    $encodedfilename = md5(time()) . '_' . $newfilename;
                    $storebase = "{$COURSE->id}/moddata/tracker/{$issue->trackerid}/{$issue->id}";
                    if (!filesystem_is_dir($storebase)) {
                        filesystem_create_dir($storebase, FS_RECURSIVE);
                    }
                    $uploader->save_files($storebase);
                    filesystem_move_file($storebase . '/' . $newfilename, $storebase . '/' . $encodedfilename);
                    $attribute->elementitemid = $encodedfilename;
                    $attributeid = insert_record('tracker_issueattribute', $attribute);
                }
            }
            if (empty($attributeid)) {
                error("Could not submit issue attribute: issue:{$issue->id} elementid:{$elementid['1']} elementitemid:{$attribute->elementitemid}");
            }
        }
    }
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:64,代码来源:locallib.php


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