Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP to mimick DirectoryIndex

Posted on 2007-10-17
2
Medium Priority
?
190 Views
Last Modified: 2007-10-17
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
0
Comment
Question by:ttist25
2 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 total points
ID: 20092952
<?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
 
LVL 1

Author Comment

by:ttist25
ID: 20092989
Schweet!

Nice job!  Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question