PHP directory contents displayer

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have the following script, which lists files within a specified web
directory (as long as they are valid extension types). It works, but I
would like the file names to be links (i.e. with hrefs) that allow you
to open that file directly from the page. Purpose of the script is
purely to display a list of photos within the directory, with links to
view those photos. PHP is not my strong-point. Any suggestions would
be very gratefully received... Here's the script....

//This function retrieves all files within a directory (non recursive)
and outputs them onto the page
//You can limit the type of files to retrieve, such as images only, as
dictated by the file's extension

function getfiles($dirname=".") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image
$files = array();
if($handle = opendir($dirname)) {
   while(false !== ($file = readdir($handle))){
      if(eregi($pattern, $file)) //if this file is a valid image
         echo "$file <br />";

getfiles(); //List all image files within the directory the PHP script
is in
getfiles("/home/myserver/public_html/george"); //List all image files
within a specific directory on the server

Re: PHP directory contents displayer contained the following:

Quoted text here. Click to load it

echo "<a href='$file'>$file</a><br />";

Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs

Site Timeline