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


PHP DirectoryIterator::key方法代碼示例

本文整理匯總了PHP中DirectoryIterator::key方法的典型用法代碼示例。如果您正苦於以下問題:PHP DirectoryIterator::key方法的具體用法?PHP DirectoryIterator::key怎麽用?PHP DirectoryIterator::key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DirectoryIterator的用法示例。


在下文中一共展示了DirectoryIterator::key方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: key

 /**
  * Return the pathname for the current resource.
  *
  * @return string The pathname of the resource or null if no resource exists.
  */
 public function key()
 {
     if (!$this->valid()) {
         return null;
     }
     return $this->iterator->key();
 }
開發者ID:mohiva,項目名稱:common,代碼行數:12,代碼來源:FilesystemResourceContainer.php

示例2: scanFolder

 protected function scanFolder($folder, &$position, $forFolders = true, $threshold_key = 'dir', $threshold_default = 50)
 {
     $registry = AEFactory::getConfiguration();
     // Initialize variables
     $arr = array();
     $false = false;
     if (!is_dir($folder) && !is_dir($folder . '/')) {
         return $false;
     }
     try {
         $di = new DirectoryIterator($folder);
     } catch (Exception $e) {
         $this->setWarning('Unreadable directory ' . $folder);
         return $false;
     }
     if (!$di->valid()) {
         $this->setWarning('Unreadable directory ' . $folder);
         return $false;
     }
     if (!empty($position)) {
         $di->seek($position);
         if ($di->key() != $position) {
             $position = null;
             return $arr;
         }
     }
     $counter = 0;
     $maxCounter = $registry->get("engine.scan.large.{$threshold_key}_threshold", $threshold_default);
     while ($di->valid()) {
         if ($di->isDot()) {
             $di->next();
             continue;
         }
         if ($di->isDir() != $forFolders) {
             $di->next();
             continue;
         }
         $ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
         $dir = $folder . $ds . $di->getFilename();
         $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir;
         if ($data) {
             $counter++;
             $arr[] = $data;
         }
         if ($counter == $maxCounter) {
             break;
         } else {
             $di->next();
         }
     }
     // Determine the new value for the position
     $di->next();
     if ($di->valid()) {
         $position = $di->key() - 1;
     } else {
         $position = null;
     }
     return $arr;
 }
開發者ID:WineWorld,項目名稱:joomlatrialcmbg,代碼行數:59,代碼來源:large.php

示例3: key

 function key()
 {
     echo __METHOD__ . "\n";
     return parent::key();
 }
開發者ID:gleamingthecube,項目名稱:php,代碼行數:5,代碼來源:ext_phar_tests_phar_oo_004U.php

示例4: _filestackProcessDir

 private function _filestackProcessDir($dir)
 {
     $Iterator = new \DirectoryIterator($dir);
     if ($this->_filestackKey > 0) {
         $Iterator->seek($this->_filestackKey);
     }
     while ($Iterator->valid()) {
         // timeout check:
         if ($this->intervalLimitIsReached() === true) {
             $this->_Dirstack->save();
             $this->_Filestack->save();
             $this->setMessage('Filestack creation: ' . $this->_filesInStack . ' files processed.');
             return false;
         }
         $this->_filestackKey = $Iterator->key();
         $this->Storage->set('filestackKey', $this->_filestackKey, 'filecheck');
         // skip dots:
         if ($Iterator->isDot()) {
             $Iterator->next();
             continue;
         }
         // if is directory save to database for later processing:
         $currentPath = $Iterator->getPathname();
         if ($Iterator->isDir()) {
             $this->_Dirstack->addPath($currentPath);
             $Iterator->next();
             continue;
         }
         // filesize check:
         $filesize = $Iterator->getSize();
         if (empty($filesize) || $filesize > $this->sizeFilter) {
             $Iterator->next();
             continue;
         }
         // filetype check:
         if ($this->_extensionCheck === true) {
             $fileExtension = $Iterator->getExtension();
             if (empty($fileExtension) || !isset($this->_allowedExtensions[$fileExtension])) {
                 $Iterator->next();
                 continue;
             }
         }
         // add file to stack:
         $this->_Filestack->addPath($currentPath);
         // create hash (if not yet done):
         if ($this->_createFilehashDb === true) {
             $pathhash = sha1($currentPath);
             $filehash = sha1_file($currentPath);
             $this->Database->setQuery("INSERT IGNORE INTO #__wm_filehashes (pathhash, filehash, mode) VALUES(" . $this->Database->q($pathhash) . "," . $this->Database->q($filehash) . ", " . $this->Database->q($this->runMode) . ")")->execute();
         }
         $this->_filesInStack++;
         $this->Storage->set('filesInStack', $this->_filesInStack, 'filecheck');
         $Iterator->next();
     }
     unset($Iterator);
     // current dir completed -> delete from stack:
     $this->_Dirstack->save();
     $this->_Dirstack->clear();
     $this->_Filestack->save();
     $this->_Filestack->clear();
     $this->Database->setQuery("DELETE FROM #__wm_dirstack WHERE path = " . $this->Database->q($dir) . "AND mode = " . $this->Database->q($this->runMode))->execute();
     $this->_filestackKey = 0;
     // select next dir from stack:
     $this->Database->setQuery("SELECT path FROM #__wm_dirstack WHERE mode = " . $this->Database->q($this->runMode) . " LIMIT 1")->execute();
     $row = $this->Database->getRow();
     if (empty($row)) {
         return true;
     }
     $this->_filestackPath = $row->path;
     $this->Storage->set('filestackPath', $this->_filestackPath, 'filecheck');
     return $this->_filestackProcessDir($row->path);
 }
開發者ID:ProjectArmy,項目名稱:wp_wemahu,代碼行數:72,代碼來源:class.audit_filecheck.php

示例5: DirectoryIterator

<?php

$a = new DirectoryIterator(__DIR__);
$b = clone $a;
var_dump((string) $b == (string) $a);
var_dump($a->key(), $b->key());
$a->next();
$a->next();
$a->next();
$c = clone $a;
var_dump((string) $c == (string) $a);
var_dump($a->key(), $c->key());
?>
===DONE===
開發者ID:badlamer,項目名稱:hhvm,代碼行數:14,代碼來源:dit_004.php

示例6: DirectoryIterator

<?php

$dir = new DirectoryIterator('./images');
session_start();
if (!isset($_SESSION['imageid'])) {
    $_SESSION['imageid'] = 0;
}
$dir->seek($_SESSION['imageid']);
do {
    $dir->next();
    //loop back to 0
    if (!$dir->valid()) {
        $dir->seek(0);
    }
} while (!$dir->isFile() || !$dir->valid() || !exif_imagetype($dir->getPathname()));
//it's not an image
$_SESSION['imageid'] = $dir->key();
//echo $dir->key();
echo './images/' . $dir->getFilename();
//imagejpeg('./images/'.$fileinfo-getFilename(), NULL,100);
開發者ID:WMTU,項目名稱:DJDisplayBoard,代碼行數:20,代碼來源:images.php

示例7: DirectoryIterator

<?php

$dit = new DirectoryIterator(__DIR__);
$dit->seek(5);
echo $dit->key(), PHP_EOL;
$dit->seek(4);
echo $dit->key(), PHP_EOL;
開發者ID:badlamer,項目名稱:hhvm,代碼行數:7,代碼來源:DirectoryIterator_seek.php

示例8:

          echo '<tr><td>isDir()</td><td> '; var_dump($item->isDir()); echo '</td></tr>';
          echo '<tr><td>isLink()</td><td> '; var_dump($item->isLink()); echo '</td></tr>';
          echo '<tr><td>getFileInfo()</td><td> '; var_dump($item->getFileInfo()); echo '</td></tr>';
          echo '<tr><td>getPathInfo()</td><td> '; var_dump($item->getPathInfo()); echo '</td></tr>';
          echo '<tr><td>openFile()</td><td> '; var_dump($item->openFile()); echo '</td></tr>';
          echo '<tr><td>setFileClass()</td><td> '; var_dump($item->setFileClass()); echo '</td></tr>';
          echo '<tr><td>setInfoClass()</td><td> '; var_dump($item->setInfoClass()); echo '</td></tr>';*/
    }
}
echo '</table>';
// while 循環
$directoryIt->rewind();
while ($directoryIt->valid()) {
    // 過濾 . 和 ..
    if (!$directoryIt->isDot()) {
        echo $directoryIt->key(), '=>', $directoryIt->current(), '<br />';
    }
    $directoryIt->next();
}
// 獲得該目錄的所有文件和下級文件夾的文件
/*$rdIt = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/data/www/yii2/learn/backend'));
foreach ($rdIt AS $name => $object) {
    echo $object.'<br/>';
}*/
echo '----------------------------------- DirectoryIterator END ---------------------------------', '<br />';
echo '--------------------------------- SimpleXMLIterator START-----------------------------------', '<br />';
/**
 * SimpleXMLIterator 遍曆xml文件
 *
 */
try {
開發者ID:ray0916,項目名稱:learn,代碼行數:31,代碼來源:iterator.php

示例9: DirectoryIterator

<?php

/*** create a new iterator object ***/
$it = new DirectoryIterator('./');
/*** loop directly over the object ***/
while ($it->valid()) {
    /*** check if value is a directory ***/
    if ($it->isDir()) {
        /*** echo the key and current value ***/
        echo $it->key() . ' -- ' . $it->current() . '<br />';
    }
    /*** move to the next iteration ***/
    $it->next();
}
開發者ID:Birjemin,項目名稱:Study,代碼行數:14,代碼來源:demo4_rename.php


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