You are here: PHP directory contents displayer « PHP Programming Language « IT news, forums, messages
PHP directory contents displayer

Posted by andrew on 03/30/07 15:32

Hi

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
extensions
$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 />";
}

closedir($handle);
}
return($files);
}
//EXAMPLE USAGE:
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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация