Flamerule
07-06-2002, 07:09 AM
Is there a way to get a list of files(a,d directories) in a specific directory.
Suppose in directory images/ you have:
icon.gif
bla.jpg
simeys/
Is there anyway to get a list of those 3 items in php?
$opdir = opendir('gallery/bigpics');
while (false!==($file = readdir($opdir))) {
if($file!=="." && $file!=="..") {
echo 'I found .......'.$file.'
';
}
}
closedir($opdir);
basically, open directory, read directory, test that the file found
isn't named dot or dotdot (dot '.' is the directories name - eg a
file telling the dir what its own name is, dotdot '..' is something to
do with the parent directory -- or so I'm led to believe) and echo
it, then close the directory.
change the opendir('xxxxxxxxxxx') to target your named
directory - you could use opendir('.') to scan the dir that the file
is in.
The above would show subdirectories as well as files. If you only
wanted files....
if(strpos($file,'.') && $file!=="." && $file!=="..")
should do.