當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RecursiveDirectoryIterator類代碼示例

本文整理匯總了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;
}
開發者ID:phn007,項目名稱:BuildHtml,代碼行數:35,代碼來源:zip.php

示例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;
     }
 }
開發者ID:arnedesmedt,項目名稱:tuinhier-ichtegem,代碼行數:33,代碼來源:fotosController.php

示例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;
 }
開發者ID:TF-Joynic,項目名稱:Hydrogen,代碼行數:34,代碼來源:ConsoleHelper.php

示例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();
    }
開發者ID:dangerdan,項目名稱:Dropplets2,代碼行數:58,代碼來源:PostManager.php

示例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);
}
開發者ID:kaizensoze,項目名稱:chips-challenge,代碼行數:11,代碼來源:chip.php

示例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));
 }
開發者ID:austinvernsonger,項目名稱:cms,代碼行數:19,代碼來源:Pages.php

示例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();
        }
    }
}
開發者ID:RoryStolzenberg,項目名稱:spacexstats,代碼行數:12,代碼來源:routes.php

示例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;
 }
開發者ID:niallcreech,項目名稱:vsmg,代碼行數:30,代碼來源:VSMGFileHelper.php

示例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);
 }
開發者ID:elibyy,項目名稱:zip,代碼行數:23,代碼來源:TestCase.php

示例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());
     }
 }
開發者ID:zhengxiexie,項目名稱:wordpress,代碼行數:11,代碼來源:IgnorantRecursiveDirectoryIterator.php

示例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');
     }
 }
開發者ID:magical-yuri,項目名稱:magical-girl,代碼行數:24,代碼來源:MasterDBImporter.php

示例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;
 }
開發者ID:leotaillard,項目名稱:btws2016,代碼行數:24,代碼來源:Garbagecollector.class.php

示例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;
             }
         }
     }
 }
開發者ID:clockworkgeek,項目名稱:magei18n,代碼行數:18,代碼來源:RecursiveSourcesIterator.php

示例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;
 }
開發者ID:joryphillips,項目名稱:bludit-plugins,代碼行數:44,代碼來源:plugin.php

示例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);
 }
開發者ID:superbalist,項目名稱:php-money,代碼行數:25,代碼來源:FileIndex.php


注:本文中的RecursiveDirectoryIterator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。