Using php to display the file names within a folder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cj2000
Forum Newbie
Posts: 7
Joined: Wed Jul 23, 2003 8:01 am

Using php to display the file names within a folder

Post by cj2000 »

Hello guys,

I'm wondering how to display the file names (and possibly generating links to them) in a folder using php.

What I'm trying to do here is to allow people to upload some pictures onto my server and also be able to generate the latest list. I'm trying to avoid using database as I don't see the need to go to that extent.

So, I'm wondering if php can return the file names. Thanks!!

cj2000
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<?php
$folder = "delta\gaming\gaming\gallery_files";
/* no need to edit the settings below */
if($handle = opendir($folder))
{
while($files = readdir($handle))
{
if ($files != "." 
&& $files != "..")
{
echo '<a href="'.$folder.'/'.$files.'">'.$files.'</a> '."<br>\n";
}
}
}
?>

there u go...this will list all files in the a folder so either u should only put images in there or edit this script to allow only images to be showen :).
Post Reply