本文整理汇总了PHP中stored_file::extract_to_storage方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::extract_to_storage方法的具体用法?PHP stored_file::extract_to_storage怎么用?PHP stored_file::extract_to_storage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stored_file
的用法示例。
在下文中一共展示了stored_file::extract_to_storage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_from_archive
public static function create_from_archive(gallery $gallery, \stored_file $storedfile, $formdata = array())
{
global $DB;
$context = $gallery->get_collection()->context;
$maxitems = $gallery->get_collection()->maxitems;
$count = $DB->count_records('mediagallery_item', array('galleryid' => $gallery->id));
if ($maxitems != 0 && $count >= $maxitems) {
return;
}
$fs = get_file_storage();
$packer = get_file_packer('application/zip');
$fs->delete_area_files($context->id, 'mod_mediagallery', 'unpacktemp', 0);
$storedfile->extract_to_storage($packer, $context->id, 'mod_mediagallery', 'unpacktemp', 0, '/');
$itemfiles = $fs->get_area_files($context->id, 'mod_mediagallery', 'unpacktemp', 0);
$storedfile->delete();
foreach ($itemfiles as $storedfile) {
if ($storedfile->get_filesize() == 0 || preg_match('#^/.DS_Store|__MACOSX/#', $storedfile->get_filepath())) {
continue;
}
if ($maxitems != 0 && $count >= $maxitems) {
break;
}
$filename = $storedfile->get_filename();
// Create an item.
$data = new \stdClass();
$data->caption = $filename;
$data->description = '';
$data->display = 1;
$metafields = array('moralrights' => 1, 'originalauthor' => '', 'productiondate' => 0, 'medium' => '', 'publisher' => '', 'broadcaster' => '', 'reference' => '');
foreach ($metafields as $field => $default) {
$data->{$field} = isset($formdata->{$field}) ? $formdata->{$field} : $default;
}
$data->galleryid = $gallery->id;
if (!$count) {
$data->thumbnail = 1;
$count = 0;
}
$item = self::create($data);
// Copy the file into the correct area.
$fileinfo = array('contextid' => $context->id, 'component' => 'mod_mediagallery', 'filearea' => 'item', 'itemid' => $item->id, 'filepath' => '/', 'filename' => $filename);
if (!$fs->get_file($context->id, 'mod_mediagallery', 'item', $item->id, '/', $filename)) {
$storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
}
$item->generate_image_by_type('lowres');
$item->generate_image_by_type('thumbnail');
$count++;
}
$fs->delete_area_files($context->id, 'mod_mediagallery', 'unpacktemp', 0);
}