simple script question

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
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

simple script question

Post by Sevengraff »

i know its possible, and im sure its easy, but how do i use php to list all the files in a directory and have it link to the files it lists? I looked at places like hotscripts.com but couldn't find anything. Please help.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

$arraycounter=0;
$DirHandle = opendir(".");
 
while ( $filesread = readdir($DirHandle) ) {
        $filesї$arraycounter]=$filesread;
        $arraycounter++;
}
closedir($DirHandle);
 
sort($files, SORT_STRING);
$arraycounter=0;
while ( $file = $filesї$arraycounter] ) {
        $arraycounter++;
 
        if ( ( $file != "index.htm" ) && ( $file != "style.css") ) { // remove unwanted files from list
 
               if (!is_dir($file)) {  // remove directories from list
                   echo "<A HREF="$file">$file</A>\n<BR>\n";
               &#125;
 
      &#125;
 
&#125;
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

thanks!
Post Reply