php - How to retrieve all text files from multiple different directories? -
you may have heard of glob
method manages retrieve files directory file containing method located on - 1 directory.
this example of code using:
<?php foreach (glob("*.txt") $filename) { $time = filemtime($filename); $files[$time] = $filename; } krsort($files); foreach ($files $file) { echo $file; } ?>
what happens here of text files in current directory retrieved, sorted order of date modified , echoed out onto page.
the problem don't want retrieve text files one directory.
how change can retrieve files multiple directories of choice 1 page - can echo out of text files multiple directories onto 1 page rather echoing out text files one directory?
i believe need store directories want glob array not sure how retrieve it.
here example stolen page in comment above
<?php $directory = new recursivedirectoryiterator('path/to/project/'); $iterator = new recursiveiteratoriterator($directory); $regex = new regexiterator($iterator, '/^.+\.txt$/i', recursiveregexiterator::get_match); ?>
Comments
Post a Comment