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


PHP get_file_packer函数代码示例

本文整理汇总了PHP中get_file_packer函数的典型用法代码示例。如果您正苦于以下问题:PHP get_file_packer函数的具体用法?PHP get_file_packer怎么用?PHP get_file_packer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: lightboxgallery_add_images

function lightboxgallery_add_images($stored_file, $context, $cm, $gallery, $resize = 0)
{
    require_once dirname(__FILE__) . '/imageclass.php';
    $fs = get_file_storage();
    $images = array();
    if ($stored_file->get_mimetype() == 'application/zip') {
        // Unpack.
        $packer = get_file_packer('application/zip');
        $fs->delete_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
        $stored_file->extract_to_storage($packer, $context->id, 'mod_lightboxgallery', 'unpacktemp', 0, '/');
        $images = $fs->get_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
        $stored_file->delete();
    } else {
        $images[] = $stored_file;
    }
    foreach ($images as $stored_file) {
        if ($stored_file->is_valid_image()) {
            $filename = $stored_file->get_filename();
            $fileinfo = array('contextid' => $context->id, 'component' => 'mod_lightboxgallery', 'filearea' => 'gallery_images', 'itemid' => 0, 'filepath' => '/', 'filename' => $filename);
            if (!$fs->get_file($context->id, 'mod_lightboxgallery', 'gallery_images', 0, '/', $filename)) {
                $stored_file = $fs->create_file_from_storedfile($fileinfo, $stored_file);
                $image = new lightboxgallery_image($stored_file, $gallery, $cm);
                if ($resize > 0) {
                    $resizeoptions = lightboxgallery_resize_options();
                    list($width, $height) = explode('x', $resizeoptions[$resize]);
                    $image->resize_image($width, $height);
                }
                $image->set_caption($filename);
            }
        }
    }
    $fs->delete_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
}
开发者ID:ndunand,项目名称:moodle-mod_lightboxgallery,代码行数:33,代码来源:locallib.php

示例2: process_attachments

 static function process_attachments($context, $email, $table, $id)
 {
     global $CFG, $USER;
     $base_path = "block_quickmail/{$USER->id}";
     $moodle_base = "{$CFG->tempdir}/{$base_path}";
     if (!file_exists($moodle_base)) {
         mkdir($moodle_base, $CFG->directorypermissions, true);
     }
     $zipname = $zip = $actual_zip = '';
     if (!empty($email->attachment)) {
         $zipname = "attachment.zip";
         $actual_zip = "{$moodle_base}/{$zipname}";
         $safe_path = preg_replace('/\\//', "\\/", $CFG->dataroot);
         $zip = preg_replace("/{$safe_path}\\//", '', $actual_zip);
         $packer = get_file_packer();
         $fs = get_file_storage();
         $files = $fs->get_area_files($context->id, 'block_quickmail', 'attachment_' . $table, $id, 'id');
         $stored_files = array();
         foreach ($files as $file) {
             if ($file->is_directory() and $file->get_filename() == '.') {
                 continue;
             }
             $stored_files[$file->get_filepath() . $file->get_filename()] = $file;
         }
         $packer->archive_to_pathname($stored_files, $actual_zip);
     }
     return array($zipname, $zip, $actual_zip);
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:28,代码来源:lib.php

示例3: booktool_exportimscp_build_package

/**
 * Export one book as IMSCP package
 *
 * @param stdClass $book book instance
 * @param context_module $context
 * @return bool|stored_file
 */
function booktool_exportimscp_build_package($book, $context)
{
    global $DB;
    $fs = get_file_storage();
    if ($packagefile = $fs->get_file($context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip')) {
        return $packagefile;
    }
    // fix structure and test if chapters present
    if (!book_preload_chapters($book)) {
        print_error('nochapters', 'booktool_exportimscp');
    }
    // prepare temp area with package contents
    booktool_exportimscp_prepare_files($book, $context);
    $packer = get_file_packer('application/zip');
    $areafiles = $fs->get_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision, "sortorder, itemid, filepath, filename", false);
    $files = array();
    foreach ($areafiles as $file) {
        $path = $file->get_filepath() . $file->get_filename();
        $path = ltrim($path, '/');
        $files[$path] = $file;
    }
    unset($areafiles);
    $packagefile = $packer->archive_to_storage($files, $context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip');
    // drop temp area
    $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision);
    // delete older versions
    $sql = "SELECT DISTINCT itemid\n              FROM {files}\n             WHERE contextid = :contextid AND component = 'booktool_exportimscp' AND itemid < :revision";
    $params = array('contextid' => $context->id, 'revision' => $book->revision);
    $revisions = $DB->get_records_sql($sql, $params);
    foreach ($revisions as $rev => $unused) {
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $rev);
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'package', $rev);
    }
    return $packagefile;
}
开发者ID:evltuma,项目名称:moodle,代码行数:42,代码来源:locallib.php

示例4: backup_course

 /**
  * Backup a course and return its backup ID.
  *
  * @param int $courseid The course ID.
  * @param int $userid The user doing the backup.
  * @return string
  */
 protected function backup_course($courseid, $userid = 2)
 {
     global $CFG;
     $packer = get_file_packer('application/vnd.moodle.backup');
     $bc = new backup_controller(backup::TYPE_1COURSE, $courseid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
     $bc->execute_plan();
     $results = $bc->get_results();
     $results['backup_destination']->extract_to_pathname($packer, "{$CFG->tempdir}/backup/core_course_testcase");
     $bc->destroy();
     unset($bc);
     return 'core_course_testcase';
 }
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:restore_test.php

示例5: test_archive_with_both_options

 public function test_archive_with_both_options()
 {
     global $CFG;
     $this->resetAfterTest();
     // Get backup packer.
     $packer = get_file_packer('application/vnd.moodle.backup');
     require_once $CFG->dirroot . '/lib/filestorage/tgz_packer.php';
     if (!tgz_packer::has_required_extension()) {
         $this->markTestSkipped('zlib not available');
         return;
     }
     // Set up basic archive contents.
     $files = array('1.txt' => array('frog'));
     // Create 2 archives (each with one file in) in default mode.
     $CFG->enabletgzbackups = false;
     $filefalse = $CFG->tempdir . '/false.mbz';
     $this->assertNotEmpty($packer->archive_to_pathname($files, $filefalse));
     $context = context_system::instance();
     $this->assertNotEmpty($storagefalse = $packer->archive_to_storage($files, $context->id, 'phpunit', 'data', 0, '/', 'false.mbz'));
     // Create 2 archives in tgz mode.
     $CFG->enabletgzbackups = true;
     $filetrue = $CFG->tempdir . '/true.mbz';
     $this->assertNotEmpty($packer->archive_to_pathname($files, $filetrue));
     $context = context_system::instance();
     $this->assertNotEmpty($storagetrue = $packer->archive_to_storage($files, $context->id, 'phpunit', 'data', 0, '/', 'false.mbz'));
     // Check the sizes are different (indicating different formats).
     $this->assertNotEquals(filesize($filefalse), filesize($filetrue));
     $this->assertNotEquals($storagefalse->get_filesize(), $storagetrue->get_filesize());
     // Extract files into storage and into filesystem from both formats.
     // (Note: the setting does not matter, but set to false just to check.)
     $CFG->enabletgzbackups = false;
     // Extract to path (zip).
     $packer->extract_to_pathname($filefalse, $CFG->tempdir);
     $onefile = $CFG->tempdir . '/1.txt';
     $this->assertEquals('frog', file_get_contents($onefile));
     unlink($onefile);
     // Extract to path (tgz).
     $packer->extract_to_pathname($filetrue, $CFG->tempdir);
     $onefile = $CFG->tempdir . '/1.txt';
     $this->assertEquals('frog', file_get_contents($onefile));
     unlink($onefile);
     // Extract to storage (zip).
     $packer->extract_to_storage($storagefalse, $context->id, 'phpunit', 'data', 1, '/');
     $fs = get_file_storage();
     $out = $fs->get_file($context->id, 'phpunit', 'data', 1, '/', '1.txt');
     $this->assertNotEmpty($out);
     $this->assertEquals('frog', $out->get_content());
     // Extract to storage (tgz).
     $packer->extract_to_storage($storagetrue, $context->id, 'phpunit', 'data', 2, '/');
     $out = $fs->get_file($context->id, 'phpunit', 'data', 2, '/', '1.txt');
     $this->assertNotEmpty($out);
     $this->assertEquals('frog', $out->get_content());
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:53,代码来源:mbz_packer_test.php

示例6: zip_attachments

 static function zip_attachments($context, $table, $id)
 {
     global $CFG, $USER;
     $base_path = "block_quickmail/{$USER->id}";
     $moodle_base = "{$CFG->tempdir}/{$base_path}";
     if (!file_exists($moodle_base)) {
         mkdir($moodle_base, $CFG->directorypermissions, true);
     }
     $zipname = "attachment.zip";
     $actual_zip = "{$moodle_base}/{$zipname}";
     $fs = get_file_storage();
     $packer = get_file_packer();
     $files = $fs->get_area_files($context->id, 'block_quickmail', 'attachment_' . $table, $id, 'id');
     $stored_files = array();
     foreach ($files as $file) {
         if ($file->is_directory() and $file->get_filename() == '.') {
             continue;
         }
         $stored_files[$file->get_filepath() . $file->get_filename()] = $file;
     }
     $packer->archive_to_pathname($stored_files, $actual_zip);
     return $actual_zip;
 }
开发者ID:nadavkav,项目名称:quickmail,代码行数:23,代码来源:lib.php

示例7: test_course_restored_event

 /**
  * Test that triggering a course_restored event works as expected.
  */
 public function test_course_restored_event()
 {
     global $CFG;
     // Get the necessary files to perform backup and restore.
     require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
     require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
     $this->resetAfterTest();
     // Set to admin user.
     $this->setAdminUser();
     // The user id is going to be 2 since we are the admin user.
     $userid = 2;
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Create backup file and save it to the backup location.
     $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
     $bc->execute_plan();
     $results = $bc->get_results();
     $file = $results['backup_destination'];
     $fp = get_file_packer('application/vnd.moodle.backup');
     $filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
     $file->extract_to_pathname($fp, $filepath);
     $bc->destroy();
     unset($bc);
     // Now we want to catch the restore course event.
     $sink = $this->redirectEvents();
     // Now restore the course to trigger the event.
     $rc = new restore_controller('test-restore-course-event', $course->id, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid, backup::TARGET_NEW_COURSE);
     $rc->execute_precheck();
     $rc->execute_plan();
     // Capture the event.
     $events = $sink->get_events();
     $sink->close();
     // Validate the event.
     $event = array_pop($events);
     $this->assertInstanceOf('\\core\\event\\course_restored', $event);
     $this->assertEquals('course', $event->objecttable);
     $this->assertEquals($rc->get_courseid(), $event->objectid);
     $this->assertEquals(context_course::instance($rc->get_courseid())->id, $event->contextid);
     $this->assertEquals('course_restored', $event->get_legacy_eventname());
     $legacydata = (object) array('courseid' => $rc->get_courseid(), 'userid' => $rc->get_userid(), 'type' => $rc->get_type(), 'target' => $rc->get_target(), 'mode' => $rc->get_mode(), 'operation' => $rc->get_operation(), 'samesite' => $rc->is_samesite());
     $url = new moodle_url('/course/view.php', array('id' => $event->objectid));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventLegacyData($legacydata, $event);
     $this->assertEventContextNotUsed($event);
     // Destroy the resource controller since we are done using it.
     $rc->destroy();
     unset($rc);
 }
开发者ID:uniedpa,项目名称:moodle,代码行数:51,代码来源:courselib_test.php

示例8: process_attachments

 /**
  * Process the attached file(s). If multiple files, create a zip file.
  */
 public static function process_attachments($context, $email, $table, $id)
 {
     global $CFG, $USER;
     $base_path = "block_clampmail/{$USER->id}";
     $moodle_base = "{$CFG->tempdir}/{$base_path}";
     if (!file_exists($moodle_base)) {
         mkdir($moodle_base, $CFG->directorypermissions, true);
     }
     $filename = $file = $actual_file = '';
     if (!empty($email->attachment)) {
         $fs = get_file_storage();
         $stored_files = array();
         $safe_path = preg_replace('/\\//', "\\/", $CFG->dataroot);
         $base_file_path = preg_replace("/{$safe_path}\\//", '', $moodle_base);
         $files = $fs->get_area_files($context->id, 'block_clampmail', 'attachment_' . $table, $id, 'id');
         // Cycle through files.
         foreach ($files as $item) {
             if ($item->is_directory() && $item->get_filename() == '.') {
                 continue;
             }
             $stored_files[$item->get_filepath() . $item->get_filename()] = $item;
         }
         // Create a zip archive if more than one file.
         if (count($stored_files) == 1) {
             $obj = current($stored_files);
             $filename = $obj->get_filename();
             $file = $base_file_path . '/' . $filename;
             $actual_file = $moodle_base . '/' . $filename;
             $obj->copy_content_to($actual_file);
         } else {
             $filename = 'attachment.zip';
             $file = $base_file_path . '/' . $filename;
             $actual_file = $moodle_base . '/' . $filename;
             $packer = get_file_packer();
             $packer->archive_to_pathname($stored_files, $actual_file);
         }
     }
     return array($filename, $file, $actual_file);
 }
开发者ID:jasonalley,项目名称:clampmail,代码行数:42,代码来源:lib.php

示例9: define_execution

 protected function define_execution()
 {
     // Get basepath
     $basepath = $this->get_basepath();
     // Get the list of files in directory
     $filestemp = get_directory_list($basepath, '', false, true, true);
     $files = array();
     foreach ($filestemp as $file) {
         // Add zip paths and fs paths to all them
         $files[$file] = $basepath . '/' . $file;
     }
     // Calculate the zip fullpath (in OS temp area it's always backup.mbz)
     $zipfile = $basepath . '/backup.imscc';
     // Get the zip packer
     $zippacker = get_file_packer('application/zip');
     // Zip files
     $zippacker->archive_to_pathname($files, $zipfile);
 }
开发者ID:nickread,项目名称:moodle,代码行数:18,代码来源:backuplib.php

示例10: validation

 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $type = $data['scormtype'];
     if ($type === SCORM_TYPE_LOCAL) {
         if (!empty($data['update'])) {
             //ok, not required
         } else {
             if (empty($files['packagefile'])) {
                 $errors['packagefile'] = get_string('required');
             } else {
                 $packer = get_file_packer('application/zip');
                 $filelist = $packer->list_files($files['packagefile']);
                 if (!is_array($filelist)) {
                     $errors['packagefile'] = 'Incorrect file package - not an archive';
                     //TODO: localise
                 } else {
                     $manifestpresent = false;
                     $aiccfound = false;
                     foreach ($filelist as $info) {
                         if ($info->pathname == 'imsmanifest.xml') {
                             $manifestpresent = true;
                             break;
                         }
                         if (preg_match('/\\.cst$/', $info->pathname)) {
                             $aiccfound = true;
                             break;
                         }
                     }
                     if (!$manifestpresent and !$aiccfound) {
                         $errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure';
                         //TODO: localise
                     }
                 }
             }
         }
     } else {
         if ($type === SCORM_TYPE_EXTERNAL) {
             $reference = $data['packageurl'];
             if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*\\/imsmanifest.xml$/i', $reference)) {
                 $errors['packageurl'] = get_string('required');
                 // TODO: improve help
             }
         } else {
             if ($type === 'packageurl') {
                 $reference = $data['reference'];
                 if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*(\\.zip|\\.pif)$/i', $reference)) {
                     $errors['packageurl'] = get_string('required');
                     // TODO: improve help
                 }
             } else {
                 if ($type === SCORM_TYPE_IMSREPOSITORY) {
                     $reference = $data['packageurl'];
                     if (stripos($reference, '#') !== 0) {
                         $errors['packageurl'] = get_string('required');
                     }
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:62,代码来源:mod_form.php

示例11: define_execution

 protected function define_execution()
 {
     // Get basepath
     $basepath = $this->get_basepath();
     // Get the list of files in directory
     $filestemp = get_directory_list($basepath, '', false, true, true);
     $files = array();
     foreach ($filestemp as $file) {
         // Add zip paths and fs paths to all them
         $files[$file] = $basepath . '/' . $file;
     }
     // Add the log file if exists
     $logfilepath = $basepath . '.log';
     if (file_exists($logfilepath)) {
         $files['moodle_backup.log'] = $logfilepath;
     }
     // Calculate the zip fullpath (in OS temp area it's always backup.mbz)
     $zipfile = $basepath . '/backup.mbz';
     // Get the zip packer
     $zippacker = get_file_packer('application/vnd.moodle.backup');
     // Track overall progress for the 2 long-running steps (archive to
     // pathname, get backup information).
     $reporter = $this->task->get_progress();
     $reporter->start_progress('backup_zip_contents', 2);
     // Zip files
     $result = $zippacker->archive_to_pathname($files, $zipfile, true, $this);
     // If any sub-progress happened, end it.
     if ($this->startedprogress) {
         $this->task->get_progress()->end_progress();
         $this->startedprogress = false;
     } else {
         // No progress was reported, manually move it on to the next overall task.
         $reporter->progress(1);
     }
     // Something went wrong.
     if ($result === false) {
         @unlink($zipfile);
         throw new backup_step_exception('error_zip_packing', '', 'An error was encountered while trying to generate backup zip');
     }
     // Read to make sure it is a valid backup. Refer MDL-37877 . Delete it, if found not to be valid.
     try {
         backup_general_helper::get_backup_information_from_mbz($zipfile, $this);
     } catch (backup_helper_exception $e) {
         @unlink($zipfile);
         throw new backup_step_exception('error_zip_packing', '', $e->debuginfo);
     }
     // If any sub-progress happened, end it.
     if ($this->startedprogress) {
         $this->task->get_progress()->end_progress();
         $this->startedprogress = false;
     } else {
         $reporter->progress(2);
     }
     $reporter->end_progress();
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:55,代码来源:backup_stepslib.php

示例12: lesson_importppt_form

$data = new stdClass;
$data->id = $cm->id;
$data->pageid = $pageid;
$mform = new lesson_importppt_form();
$mform->set_data($data);

if ($data = $mform->get_data()) {
    $manager = lesson_page_type_manager::get($lesson);
    if (!$filename = $mform->get_new_filename('pptzip')) {
        print_error('invalidfile', 'lesson');
    }
    if (!$package = $mform->save_stored_file('pptzip', $context->id, 'mod_lesson', 'ppt_imports', $lesson->id, '/', $filename, true)) {
        print_error('unabletosavefile', 'lesson');
    }
    // extract package content
    $packer = get_file_packer('application/zip');
    $package->extract_to_storage($packer, $context->id, 'mod_lesson', 'imported_files', $lesson->id, '/');

    $fs = get_file_storage();
    if ($files = $fs->get_area_files($context->id, 'mod_lesson', 'imported_files', $lesson->id)) {

        $pages = array();
        foreach ($files as $key=>$file) {
            if ($file->get_mimetype() != 'text/html') {
                continue;
            }
            $filenameinfo = pathinfo($file->get_filepath().$file->get_filename());

            $page = new stdClass;
            $page->title = '';
            $page->contents = array();
开发者ID:JP-Git,项目名称:moodle,代码行数:31,代码来源:importppt.php

示例13: report_ncccscensus_generate_bulk_zip

/**
 * Generates list of zip files in array.
 *
 * @param int $batch id of batch
 * @return array|bool False on no files to add to zip, array on success
 * @uses $CFG, $DB
 */
function report_ncccscensus_generate_bulk_zip($batch)
{
    global $DB, $USER;
    // Check if last report.
    $left = $DB->count_records('report_ncccscensus', array('batchid' => $batch, 'status' => 0));
    if ($left !== 0) {
        return false;
    }
    $files = report_ncccscensus_get_zip_files($batch);
    if (!is_array($files)) {
        return false;
    }
    $date = usergetdate(time(), get_user_timezone());
    $filename = date('MdY_Hi', mktime($date['hours'], $date['minutes'], 0, $date['mon'], $date['mday'], $date['year']));
    $filename = $filename . '-' . $batch . '.zip';
    $fs = get_file_storage();
    // Check to see if file exists.
    $contextid = context_system::instance()->id;
    $file = $fs->get_file($contextid, 'report_ncccscensus', 'archive', $batch, '/report_ncccscensus/', $filename);
    if (!$file) {
        // Prepare file record object.
        $fileinfo = array('contextid' => context_system::instance()->id, 'component' => 'report_ncccscensus', 'filearea' => 'archive', 'itemid' => $batch, 'filepath' => '/report_ncccscensus/', 'filename' => $filename);
        $file = $fs->create_file_from_string($fileinfo, '');
    }
    $parentpath = $file->get_parent_directory()->get_filepath();
    $filepath = explode('/', trim($file->get_filepath(), '/'));
    $filepath = array_pop($filepath);
    // Generate zip.
    $zipper = get_file_packer('application/zip');
    $record = $DB->get_record('report_ncccscensus_batch', array('id' => $batch));
    $contextid = context_system::instance()->id;
    $path = 'report_ncccscensus';
    $newfile = $zipper->archive_to_storage($files, $contextid, $path, 'archive', $batch, $parentpath, $filename, $USER->id);
    if ($newfile) {
        // Mark batch as complete.
        $record->zipfile = $filename;
    }
    $record->status = 1;
    $DB->update_record('report_ncccscensus_batch', $record);
    $info = array();
    // Delete pdf files.
    foreach ($files as $filename => $fullfilename) {
        @unlink($fullfilename);
        $info = pathinfo($fullfilename);
    }
    if (!empty($info['dirname'])) {
        @rmdir($info['dirname']);
    }
}
开发者ID:cbmegahan,项目名称:report_ncccscensus,代码行数:56,代码来源:lib.php

示例14: validation

    function validation($data, $files) {
        global $CFG;
        $errors = parent::validation($data, $files);

        $type = $data['scormtype'];

        if ($type === SCORM_TYPE_LOCAL) {
            if (!empty($data['update'])) {
                //ok, not required

            } else if (empty($data['packagefile'])) {
                $errors['packagefile'] = get_string('required');

            } else {
                $files = $this->get_draft_files('packagefile');
                if (count($files)<1) {
                    $errors['packagefile'] = get_string('required');
                    return $errors;
                }
                $file = reset($files);
                $filename = $CFG->tempdir.'/scormimport/scrom_'.time();
                make_temp_directory('scormimport');
                $file->copy_content_to($filename);

                $packer = get_file_packer('application/zip');

                $filelist = $packer->list_files($filename);
                if (!is_array($filelist)) {
                    $errors['packagefile'] = 'Incorrect file package - not an archive'; //TODO: localise
                } else {
                    $manifestpresent = false;
                    $aiccfound       = false;
                    foreach ($filelist as $info) {
                        if ($info->pathname == 'imsmanifest.xml') {
                            $manifestpresent = true;
                            break;
                        }
                        if (preg_match('/\.cst$/', $info->pathname)) {
                            $aiccfound = true;
                            break;
                        }
                    }
                    if (!$manifestpresent and !$aiccfound) {
                        $errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure'; //TODO: localise
                    }
                }
                unlink($filename);
            }

        } else if ($type === SCORM_TYPE_EXTERNAL) {
            $reference = $data['packageurl'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        } else if ($type === 'packageurl') {
            $reference = $data['reference'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        } else if ($type === SCORM_TYPE_IMSREPOSITORY) {
            $reference = $data['packageurl'];
            if (stripos($reference, '#') !== 0) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            }

        } else if ($type === SCORM_TYPE_AICCURL) {
            $reference = $data['packageurl'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        }

        return $errors;
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:98,代码来源:mod_form.php

示例15: extract_file_to_dir

 protected function extract_file_to_dir()
 {
     global $CFG, $USER;
     $this->filepath = restore_controller::get_tempdir_name($this->contextid, $USER->id);
     $fb = get_file_packer();
     return $fb->extract_to_pathname("{$CFG->tempdir}/backup/" . $this->filename, "{$CFG->tempdir}/backup/{$this->filepath}/");
 }
开发者ID:raymondAntonio,项目名称:moodle,代码行数:7,代码来源:restore_ui_stage.class.php


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