Exemplo n.º 1
0
// file upload form sumitted
if ($form = $import_form->get_data()) {
    // file checks out ok
    $fileisgood = false;
    // work out if this is an uploaded file
    // or one from the filesarea.
    if (!empty($form->choosefile)) {
        $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}";
        if (file_exists($importfile)) {
            $fileisgood = true;
        } else {
            error(get_string('uploadproblem', 'moodle', $form->choosefile));
        }
    } else {
        // must be upload file
        if (!($importfile = $import_form->get_importfile_name())) {
            error(get_string('uploadproblem', 'moodle'));
        } else {
            $fileisgood = true;
        }
    }
    // process if we are happy file is ok
    if ($fileisgood) {
        if (!is_readable("format/{$form->format}/format.php")) {
            error(get_string('formatnotfound', 'quiz', $form->format));
        }
        require_once "format.php";
        // Parent class
        require_once "format/{$form->format}/format.php";
        $classname = "qformat_{$form->format}";
        $qformat = new $classname();
Exemplo n.º 2
0
 // work out if this is an uploaded file
 // or one from the filesarea.
 if (!empty($form->choosefile)) {
     $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}";
     $realfilename = $form->choosefile;
     if (file_exists($importfile)) {
         $fileisgood = true;
     } else {
         print_error('uploadproblem', 'moodle', $form->choosefile);
     }
 } else {
     // must be upload file
     $realfilename = $import_form->get_importfile_realname();
     // move the file into the dataroot
     $importfile = $CFG->dataroot . '/temp/' . $realfilename;
     if (move_uploaded_file($import_form->get_importfile_name(), $importfile)) {
         $fileisgood = true;
     } else {
         print_error('uploadproblem', 'moodle');
     }
 }
 // process if we are happy file is ok
 if ($fileisgood) {
     if (!is_readable("format/{$form->format}/format.php")) {
         print_error('formatnotfound', 'quiz', $form->format);
     }
     require_once "format.php";
     // Parent class
     require_once "format/{$form->format}/format.php";
     $classname = "qformat_{$form->format}";
     $qformat = new $classname();