本文整理汇总了PHP中RecursiveDirectoryIterator类的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator类的具体用法?PHP RecursiveDirectoryIterator怎么用?PHP RecursiveDirectoryIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RecursiveDirectoryIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: zipData
function zipData($source, $destination)
{
if (extension_loaded('zip')) {
if (file_exists($source)) {
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
$source = realpath($source);
if (is_dir($source)) {
$iterator = new RecursiveDirectoryIterator($source);
// skip dot files while iterating
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = realpath($file);
if (is_dir($file)) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else {
if (is_file($file)) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
} else {
if (is_file($source)) {
$zip->addFromString(basename($source), file_get_contents($source));
}
}
}
echo $destination . ' zip: successfully...';
echo "\n";
return $zip->close();
}
}
return false;
}
示例2: index
public function index()
{
parent::index();
$album = empty($this->parameters) ? "" : array_shift($this->parameters);
$dir = new \RecursiveDirectoryIterator(dirname(__DIR__) . $this->basedir . $album);
if (empty($album)) {
$albums = array();
foreach ($dir as $name => $object) {
$shortname = basename($name);
if ($shortname != ".." && $shortname != ".") {
$temp_album = new \DirectoryIterator($name);
foreach ($temp_album as $img) {
if ($img->isFile()) {
break;
}
}
$albums[$dir->getCTime()] = array("name" => $shortname, "image" => $this->basedir . $shortname . "/" . $img, "link" => "/fotos/index/" . $shortname);
}
}
ksort($albums);
$this->context["albums"] = $albums;
} else {
$pictures = array();
foreach ($dir as $image) {
$shortname = basename($image);
if ($shortname != ".." && $shortname != ".") {
$pictures[] = $this->basedir . $album . "/" . $shortname;
}
}
$this->context["pictures"] = $pictures;
$this->context["album"] = $album;
}
}
示例3: getCallableModules
/**
* get callable module list
*
* @return array
*/
public function getCallableModules()
{
$dirIterator = new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::SKIP_DOTS);
$modules = array();
foreach ($dirIterator as $k => $v) {
$doVotedModule = false;
if ($dirIterator->hasChildren()) {
foreach ($dirIterator->getChildren() as $key => $value) {
$entension = $value->getExtension();
if (!$entension || 'php' !== $entension) {
continue;
}
$fileBasename = $value->getBasename('.php');
$module_to_be = $v->getBasename();
$expectedClassName = $this->baseNamespace . NAMESPACE_SEPARATOR . $module_to_be . NAMESPACE_SEPARATOR . $fileBasename;
Loader::getInstance()->import($value->__toString());
if (!class_exists($expectedClassName, false)) {
// not a standard class file!
continue;
}
if (!$doVotedModule) {
$modules[] = $module_to_be;
$doVotedModule = true;
}
}
}
}
return $modules;
}
示例4: listPosts
public function listPosts()
{
$path = null;
$timestamp = null;
$dirname = $this->settings->posts_dir;
$dir = new \RecursiveDirectoryIterator($dirname);
$dir->setFlags(\RecursiveDirectoryIterator::SKIP_DOTS);
ob_start();
?>
<div class="row">
<table class="post-table">
<tr>
<th>Name</th>
<th>Date created</th>
</tr>
<?php
foreach ($dir as $fileinfo) {
if ($fileinfo->getMTime() > $timestamp) {
// current file has been modified more recently
// than any other file we've checked until now
$path = $fileinfo->getFilename();
$modified = $fileinfo->getMTime();
$created = $fileinfo->getCTime();
$linkUrl = preg_replace('/\\.[^.\\s]{1,4}$/', '', $path);
echo "<tr><td><a href='?action=edit&post=" . $linkUrl . "'>" . $path . "</a></td>";
echo "<td>" . date("F d Y H:i:s.", $created) . "</td></tr>";
}
}
?>
</table>
</div>
<style>
.post-table {
width: 80%;
margin: 50px auto;
text-align: center;
border: solid 1px #ddd;
}
.post-table th {
font-weight: bold;
}
.post-table th,
.post-table td {
text-align: left;
padding: 5px;
border: solid 1px #ddd;
}
</style>
<?php
return ob_get_clean();
}
示例5: show_maps
function show_maps()
{
$maps = array();
$it = new RecursiveDirectoryIterator('../maps');
foreach (new RecursiveIteratorIterator($it) as $file) {
if (!$it->isDot()) {
array_push($maps, basename($file));
}
}
echo json_encode($maps);
}
示例6: from
/**
* Create Pages object instance from path
*
* @param string $path
* @param array|callable $filter
* @param string $class
* @return \cms\Pages
*/
public static function from($path, $filter = ['index', '404'], $class = Page::class)
{
$iterator = new \RecursiveDirectoryIterator(realpath($path), \RecursiveDirectoryIterator::SKIP_DOTS);
if (class_exists($class)) {
$iterator->setInfoClass($class);
}
$filter = is_callable($filter) ? $filter : function (Page $item) use($filter) {
return $item->isValid((array) $filter);
};
return new self(new \RecursiveCallbackFilterIterator($iterator, $filter));
}
示例7: routesInDirectory
function routesInDirectory($app = '')
{
$routeDir = app_path('Http/Routes/' . $app . ($app !== '' ? '/' : NULL));
$iterator = new RecursiveDirectoryIterator($routeDir);
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($iterator as $route) {
$isDotFile = strpos($route->getFilename(), '.') === 0;
if (!$isDotFile && !$route->isDir()) {
require $routeDir . $route->getFilename();
}
}
}
示例8: getImagePaths
/**
* A function to (optionally) recursive through a root directory,
* retrieving image paths
*
* @param $folder
* The root folder to start the scanning
* @param $enable_chidren
* Boolean value to enable scanning through child folders, default to false
*
* @return
* An array of image paths
*
* @todo
* Use more robust php recursive directory search options
*/
static function getImagePaths($folder, $enable_chidren = FALSE)
{
$image_array = array();
$iterator = new RecursiveDirectoryIterator($folder);
$image_array = array_merge($image_array, VSMGFileHelper::getDirectoryImages($folder));
if ($enable_chidren) {
foreach ($iterator as $file) {
if (is_dir($file) && !$iterator->isDot()) {
// echo "VSMGFileHelper::getImagePaths DIR: $file\n";
$image_array = array_merge($image_array, VSMGFileHelper::getDirectoryImages($file));
}
}
}
return $image_array;
}
示例9: _deleteFolder
/**
* deletes a folder recursively
*
* @param string $path the folder to delete
*
* @since 1.0
*/
protected static function _deleteFolder($path)
{
/**
* @var \SplFileInfo $item
*/
$dir = new \RecursiveDirectoryIterator($path);
while ($dir->valid()) {
$item = $dir->current();
if (!in_array($item->getFilename(), array('.', '..'))) {
$isFile = $item->isFile();
$isFile ? unlink($item->getRealPath()) : self::_deleteFolder($item->getRealPath());
}
$dir->next();
}
rmdir($path);
}
示例10: getChildren
/** Override of getChildren in \RecursiveDirectoryIterator, to skip directories with insufficient rights to access
* @internal
*/
function getChildren()
{
try {
return parent::getChildren();
} catch (\UnexpectedValueException $e) {
return new \RecursiveArrayIterator(array());
}
}
示例11: import
/**
* import
*
* @param string $tsvDirPath
* @access public
* @return void
*/
public function import($tsvDirPath = null)
{
if (is_null($tsvDirPath)) {
$tsvDirPath = realpath(__DIR__ . '/../../../../../../masterData');
}
$iterator = new \RecursiveDirectoryIterator($tsvDirPath);
foreach ($iterator as $file) {
if (!$iterator->hasChildren()) {
continue;
}
$databaseName = $file->getFileName();
$con = $this->getConnection($databaseName);
$con->exec('set foreign_key_checks = 0');
$this->importFromTsvInDir($iterator->getChildren(), $con);
$con->exec('set foreign_key_checks = 1');
}
}
示例12: getOutdatedFiles
/**
* Retrieves old CSS files and list them
*
* @param $ttl int
* @return array
*/
protected function getOutdatedFiles($ttl)
{
$outdated = array();
$time = time();
$dir = new RecursiveDirectoryIterator($this->configuration->getUploadDir());
$dir->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
/*
* Collecting CSS files
*/
$files = new RegexIterator(new RecursiveIteratorIterator($dir), '#.css#U', RecursiveRegexIterator::ALL_MATCHES);
/*
* Checking expiry
*/
foreach ($files as $filepath => $match) {
filemtime($filepath) + $ttl < $time ? array_push($outdated, $filepath) : null;
}
return $outdated;
}
示例13: __construct
public function __construct(array $sources)
{
foreach ($sources as $source) {
if ($source instanceof \SplFileInfo) {
$this->children[] = $source;
} elseif (is_string($source) && ($source = realpath($source))) {
if (is_file($source)) {
$child = new SourceFileInfo($source);
$child->setInfoClass(SourceFileInfo::class);
$this->children[] = $child;
} elseif (is_dir($source)) {
$child = new \RecursiveDirectoryIterator($source);
$child->setInfoClass(SourceFileInfo::class);
$this->children[] = $child;
}
}
}
}
示例14: zipData
public function zipData($source, $destination)
{
global $Language;
$archiveName = 'backup-' . time() . '.zip';
// Archive name
if (extension_loaded('zip')) {
if (file_exists($source)) {
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
$source = realpath($source);
if (is_dir($source)) {
$iterator = new RecursiveDirectoryIterator($source);
// skip dot files while iterating
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = realpath($file);
if (is_dir($file)) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else {
if (is_file($file)) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
} else {
if (is_file($source)) {
$zip->addFromString(basename($source), file_get_contents($source));
}
}
}
if (!$zip->close()) {
Alert::set($Language->get("There was a problem writing the ZIP archive."));
Redirect::page('admin', 'configure-plugin/pluginBackup');
} else {
Alert::set($Language->get("Successfully created the ZIP Archive!"));
Redirect::page('admin', 'configure-plugin/pluginBackup');
}
// close the zip file
$zip->close();
}
}
return false;
}
示例15: make
/**
* @param string $dir
* @return FileIndex
*/
public static function make($dir)
{
$dirIterator = new \RecursiveDirectoryIterator($dir);
$dirIterator->setFlags(\RecursiveDirectoryIterator::SKIP_DOTS);
$recursiveIterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::SELF_FIRST);
$results = array();
foreach ($recursiveIterator as $file) {
/** @var \SplFileInfo $file */
// ignore non files
if (!$file->isFile()) {
continue;
}
// ignore non php files
$ext = strtolower($file->getExtension());
if ($ext !== 'php') {
continue;
}
$results[] = $file->getPathname();
}
return new self($results);
}