2010-12-11 22 views
1

ディレクトリ内のすべてのファイルを順序付きリストにリンクするindex.htmlファイルを作成します。ディレクトリの内容をすべて一覧表示するにはどうすればよいですか?

あなたがhereを行くときたとえば、あなたが見つける:

# 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 

私が何をしたい:

<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> 

のように...

+1

を参照してください。たぶん私は間違ったことを見ているが、そのリンクでハイパーリンクの順不同のリストがすでに存在しています。 – salathe

+0

[dir(PHP)のファイルとフォルダをリストする方法](http://stackoverflow.com/questions/4050511/how-to-list-files-and-folder-in-a-dir-php ) – Gordon

答えて

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); 
    } 
} 
?> 

注意すべきことは、aタグのhref値を変更する必要があります。これはほんの一例ですoあなたを始めましょう。

+0

'htmlspecialchars()'でこれらのファイル名に特殊文字をエスケープしてください... – Alnitak

+0

mateを理解できません:( – 5416339

1

How to list files from a directory with PHPhas been answered way too oftenここにもう一度お答えください。しかし、そのリンクのリストは、あなたがそのフォルダ内のファイル.htaccess

Options +Indexes 

を置くことで有効にできる、Apacheの組み込みのディレクトリのインデックスのようにたくさん見えます。以下のリンクに

関連する問題