List all files in a directory
With this codesnippet you can very easily list all the files in a directory, effectively creating a web-based filemanager (if you extend it with other functions).
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
// List all the files
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>
October 24th, 2005 at 7:28 pm
I’m a novice - i don’t kmow how to customize (I assume the red text) for my site.
November 10th, 2005 at 12:37 am
An example if you want all of a specific file type in a directory.
$GalleryDirectory = “albums/”;
foreach (glob(”$GalleryDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}”, GLOB_BRACE) as $photo)
{
echo
endHTML;
}
November 10th, 2005 at 12:40 am
Sorry it edited my code out. in the foreach echo use img src=$photo
March 31st, 2006 at 5:48 pm
Doing with foreach is better.
And the while in this case is way to complicated, with booleans and everything.
June 8th, 2006 at 9:01 pm
IS there any way to create an array of images from a specified directory (Says, /pics/)
then preload each image from the newly created array? I would also need some sort of progress bar to illuminate progression after which a redirect would be required.
Any suggestions?