1

I want to make an index.html file which links all the files in a directory in an ordered list.

For example, when you go here, you find:

# Parent Directory
# <u>lol.html
# "><script>alert(String.fromCharCode(72)-String.fromCharCode(105)).html
# -AAAAAAAAAAAAAAAAAAAATESTING.html
# 0dl.blogspot.com.html
# 1000-suns.html
# 123-greeting.html
# 151.html
# 1^2+2-.-2^2-+-3^2-+2-.-4^2.html
# 2010-IIT-JEE-Solutions-Fiitjee.html
# 2010-IIT-JEE-Solutions.html

What I want to do:

<a href="http://searchr.us/web-search/&lt%3bu&gt%3blol.html" >&lt;u&gt;lol.html</a>
<a href="http://searchr.us/web-search/&quot%3b&gt%3b&lt%3bscript&gt%3balert(String.fromCharCode(72)-String.fromCharCode(105)).html">http://searchr.us/web-search/&quot%3b&gt%3b&lt%3bscript&gt%3balert(String.fromCharCode(72)-String.fromCharCode(105)).html</a>

And so on...

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
5416339
  • 417
  • 3
  • 9
  • 18
  • 1
    Maybe I'm seeing the wrong thing, but at that link there is already an unordered list of hyperlinks. – salathe Dec 11 '10 at 10:28
  • possible duplicate of [How to list files and folder in a dir (PHP)](http://stackoverflow.com/questions/4050511/how-to-list-files-and-folder-in-a-dir-php) – Gordon Dec 11 '10 at 10:58

2 Answers2

1
<?php
$dir = getcwd();

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo '<a href="'.$_SERVER['REQUEST_URI'].'/'.$file.'">' . $file . '</a><br />';
        }
        closedir($dh);
    }
}
?>

Be carefull the href value of the a tag must be changed this is only an example to get you started .

Poelinca Dorin
  • 9,577
  • 2
  • 39
  • 43
1

How to list files from a directory with PHP has been answered way too often to answer it here again. However, the listing at that links looks a lot like Apache's built-in directory indexes, which you can enable by putting

Options +Indexes

in an .htaccess file in that folder. See the following links

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559