PHP to mimick DirectoryIndex

Hey there!

How can I modify this:

<?php
if ($handle = opendir('pics')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";

    // List all the files
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }

    closedir($handle);
}
?>

to display a list of links to files in the pics directory?

I'm trying to get the same functionality that DirectoryIndex *.* in a .htaccess file would provide but my host doesn't allow custom .htaccess files.

I'm also open to alternative methods that might be more elegant.  

TIA
LVL 1
ttist25Asked:
Who is Participating?
 
steelseth12Connect With a Mentor Commented:
<?php

$dir = "pics"; //  directory of files

if ($handle = opendir($dir)) {
    echo "Directory handle: $handle\n<br>";
    echo "Files:\n<br>";

    // List all the files
    while (false !== ($file = readdir($handle))) {
       
            if($file !=".." && $file !=".") {
            
                  echo "<a href=".$dir."/".$file.">".$file."<br>\n";
   
            }
      }

    closedir($handle);
}
?>
0
 
ttist25Author Commented:
Schweet!

Nice job!  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.