Skip to content

Instantly share code, notes, and snippets.

@xkeshav
Created December 16, 2014 13:40
Show Gist options
  • Save xkeshav/824f431a5637a1b8fbea to your computer and use it in GitHub Desktop.
Save xkeshav/824f431a5637a1b8fbea to your computer and use it in GitHub Desktop.
php SPL iterator practice
<?php
$project_dir = '/opt/lampp/htdocs/parixan/data';
$RealPath = realpath($project_dir);
var_dump($RealPath);
$Directory = new RecursiveDirectoryIterator($RealPath, FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO);
foreach ($Directory as $dir) {
if( $Directory->hasChildren() ) {
$ch = $Directory->getChildren();
// var_dump($ch->key());
$fsi = new RecursiveIteratorIterator($ch, FilesystemIterator::SKIP_DOTS | RecursiveIteratorIterator::LEAVES_ONLY );
$fsi_ = iterator_to_array($fsi, true);
// var_dump($fsi_);
krsort($fsi_);
var_dump($fsi_);
foreach ($fsi_ as $f) {
var_dump($f->getFileName());
if($f->isDir()) {
$fi = new RecursiveDirectoryIterator($f, FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO);
$It = new RecursiveIteratorIterator($fi);
$Regex = new RegexIterator($It, '#/thumbnails/.*#i', RecursiveRegexIterator::GET_MATCH);
$th = iterator_to_array($Regex);
krsort($th);
var_dump($th);
foreach($th as $v){
var_dump($v);
}
// var_dump(__LINE__,iterator_to_array($fi));
}
}
}
}
exit;
$files_ = iterator_to_array($Directory, true);
// var_dump($files_);
// // exit;
// exit;
// foreach ($files_ as $file) {
// $fsi = new RecursiveDirectoryIterator($file,
// FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS );
// $fsi_ = iterator_to_array($fsi, true);
// krsort($fsi_);
// var_dump($fsi_);
// foreach ($fsi_ as $f) {
// if($f->isDir()){
// // $d = scandir($f->getPathname(),1);
// // var_dump($d);
// $th = new RecursiveDirectoryIterator($f->getPathname().DS.'thumbnails', FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO);
// var_dump($th);
// // $fd_ = iterator_to_array($fd,true);
// // krsort($fd_);
// // var_dump($fd_);
// $format = "<br/> Directory : %s , Created at : %s , Modified at : %s<hr/>";
// printf($format, $f->getPathname(), $f->getCtime(), $f->getMtime());
// }
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment