List Files In A Directory Using PHP
by Gabi SolomonUsually Apache will list all the files in a directory that doesnt have an index, unless the -indexes option is activated. Never the less sometimes in your programing you will need to list the files that are in a directory, not on the screen necessarily but at least save those files in a variable.
But enough small talk lets gets on with the actual code :
-
<?php
-
$dirPath='/path/to/your/dir/';
-
-
{
-
if ($file != "." && $file != "..")
-
{
-
$fileList[] = $file;
-
}
-
}
-
}
-
?>
-
<h3>List of files:</h3>
-
<?php foreach ( $fileList as $f ) : ?>
-
<P><?=$f?></p>
-
<?php endforeach; ?>
Is that simple.
Cheers

