本文整理汇总了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();
}
示例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;
}
示例3: key
function key()
{
echo __METHOD__ . "\n";
return parent::key();
}
示例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);
}
示例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===
示例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);
示例7: DirectoryIterator
<?php
$dit = new DirectoryIterator(__DIR__);
$dit->seek(5);
echo $dit->key(), PHP_EOL;
$dit->seek(4);
echo $dit->key(), PHP_EOL;
示例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 {
示例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();
}