I have a directory called 25
and I want to print the list of files in that directory using PHP.
How can I ?
Priti_P
0
Junior Poster
Recommended Answers
Jump to PostTry
glob()
Jump to PostI love glob. But you could also use DirectoryIterator:
function getFiles($dir='.') { $out = ''; foreach (new DirectoryIterator($dir) as $file) { if($file->isDot() || $file->isDir()) continue; $out .= $file->getFilename() . "<br />\n"; } return $out; } echo getFiles(); echo getFiles('./includes');
Alternatively, you could store to an array:
…
All 6 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
Unimportant
18
Junior Poster
diafol
Atli
commented:
Iterators; one of the most underused feature in PHP.
+8
NardCake
30
Posting Pro in Training
diafol
Priti_P
0
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.