本文整理汇总了PHP中stored_file::list_files方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::list_files方法的具体用法?PHP stored_file::list_files怎么用?PHP stored_file::list_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stored_file
的用法示例。
在下文中一共展示了stored_file::list_files方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toolbook_importhtml_get_chapter_files
/**
* Returns all the html files (chapters) from a file package
*
* @param stored_file $package file to be processed
* @param string $type type of the package ('typezipdirs' or 'typezipfiles')
*
* @return array the html files found in the package
*/
function toolbook_importhtml_get_chapter_files($package, $type) {
$packer = get_file_packer('application/zip');
$files = $package->list_files($packer);
$tophtmlfiles = array();
$subhtmlfiles = array();
$topdirs = array();
foreach ($files as $file) {
if (empty($file->pathname)) {
continue;
}
if (substr($file->pathname, -1) === '/') {
if (substr_count($file->pathname, '/') !== 1) {
// skip subdirs
continue;
}
if (!isset($topdirs[$file->pathname])) {
$topdirs[$file->pathname] = array();
}
} else {
$mime = mimeinfo('icon', $file->pathname);
if ($mime !== 'html') {
continue;
}
$level = substr_count($file->pathname, '/');
if ($level === 0) {
$tophtmlfiles[$file->pathname] = $file;
} else if ($level === 1) {
$subhtmlfiles[$file->pathname] = $file;
$dir = preg_replace('|/.*$|', '', $file->pathname);
$topdirs[$dir][$file->pathname] = $file;
} else {
// lower levels are not interesting
continue;
}
}
}
collatorlib::ksort($tophtmlfiles, collatorlib::SORT_NATURAL);
collatorlib::ksort($subhtmlfiles, collatorlib::SORT_NATURAL);
collatorlib::ksort($topdirs, collatorlib::SORT_NATURAL);
$chapterfiles = array();
if ($type == 2) {
$chapterfiles = $tophtmlfiles;
} else if ($type == 1) {
foreach ($topdirs as $dir => $htmlfiles) {
if (empty($htmlfiles)) {
continue;
}
collatorlib::ksort($htmlfiles, collatorlib::SORT_NATURAL);
if (isset($htmlfiles[$dir.'/index.html'])) {
$htmlfile = $htmlfiles[$dir.'/index.html'];
} else if (isset($htmlfiles[$dir.'/index.htm'])) {
$htmlfile = $htmlfiles[$dir.'/index.htm'];
} else if (isset($htmlfiles[$dir.'/Default.htm'])) {
$htmlfile = $htmlfiles[$dir.'/Default.htm'];
} else {
$htmlfile = reset($htmlfiles);
}
$chapterfiles[$htmlfile->pathname] = $htmlfile;
}
} else if ($type == 0) {
if ($tophtmlfiles) {
if (isset($tophtmlfiles['index.html'])) {
$htmlfile = $tophtmlfiles['index.html'];
} else if (isset($tophtmlfiles['index.htm'])) {
$htmlfile = $tophtmlfiles['index.htm'];
} else if (isset($tophtmlfiles['Default.htm'])) {
$htmlfile = $tophtmlfiles['Default.htm'];
} else {
$htmlfile = reset($tophtmlfiles);
}
} else {
$htmlfile = reset($subhtmlfiles);
}
$chapterfiles[$htmlfile->pathname] = $htmlfile;
}
return $chapterfiles;
}
示例2: tincanlaunch_validate_package
/**
* Check that a Zip file contains a tincan.xml file in the right place. Used in mod_form.php.
* Heavily based on scorm_validate_package in /mod/scorm/lib.php
* @package mod_tincanlaunch
* @category tincan
* @param stored_file $file a Zip file.
* @return array empty if no issue is found. Array of error message otherwise
*/
function tincanlaunch_validate_package($file)
{
$packer = get_file_packer('application/zip');
$errors = array();
$filelist = $file->list_files($packer);
if (!is_array($filelist)) {
$errors['packagefile'] = get_string('badarchive', 'tincanlaunch');
} else {
$badmanifestpresent = false;
foreach ($filelist as $info) {
if ($info->pathname == 'tincan.xml') {
return array();
} elseif (strpos($info->pathname, 'tincan.xml') !== false) {
// This package has tincan xml file inside a folder of the package.
$badmanifestpresent = true;
}
if (preg_match('/\\.cst$/', $info->pathname)) {
return array();
}
}
if ($badmanifestpresent) {
$errors['packagefile'] = get_string('badimsmanifestlocation', 'tincanlaunch');
} else {
$errors['packagefile'] = get_string('nomanifest', 'tincanlaunch');
}
}
return $errors;
}