/**
  * 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();
 }
Example #2
0
 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;
 }
 function key()
 {
     echo __METHOD__ . "\n";
     return parent::key();
 }
 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);
 }
Example #5
0
<?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===
Example #6
0
<?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);
Example #7
0
<?php

$dit = new DirectoryIterator(__DIR__);
$dit->seek(5);
echo $dit->key(), PHP_EOL;
$dit->seek(4);
echo $dit->key(), PHP_EOL;
Example #8
0
          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 {
Example #9
0
<?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();
}