PHP Code:
$directory = "docs/"; $SpecialList = "yes"; //Deternime if Custom Formatting if ($SpecialList=="yes") { $DispStart = "<ul style='list-style:circle;margin:0px;'>"; //Standard Unordered List comes prepackaged! :D $DispFormat = "<li style='margin:-5px;'>"; $DispFormat2 = "</li>"; $DispEnd = "</ul>"; } echo "<h1>Oops!</h1><p>You haven't specified which article you want to look at!</p><p>Here's a list of what files I've found for you, maybe one of them will be what you are looking for.</p>"; if (is_dir($directory)) { if ($dirOpen=opendir($directory)) { while (($fileTR=readdir($dirOpen))!=false) { echo $DispStart; if (filetype($directory.$fileTR)!="dir") { $ridOfFExt=array(".php"=>"",".txt"=>"",".htm"=>"",".html"=>""); echo "$DispFormat<a href='$directory$fileTR'>".strtr(preg_replace("([A-Z]+)", " $0", $fileTR),$ridOfFExt)."</a>$DispFormat2<br />"; } echo $DispEnd; } closedir($dirOpen); } echo "<p>Please note that the files above will not be formatted. You will see the entire file. Thank you.</p>"; } else { echo "Invalid Directory."; }
So basically what this does is display all the files in a specified directory, and lets you go to them. It's useful for error pages, where it says 'File not found, but here's what I DID find' kind of thing.
Hopefully somebody finds it useful!
How it works:
It works by opening the specified directory (using the $directory variable) and reading out the contents using a PHP function. It then formats the name from say, RandomFile.htm to Random File. It also provides a link to RandomFile.htm.
It senses capital letters and replaces them with a space. Now instead of getting the standard ugly NOT FOUND Apache message, you can use this!
Update 1.1 - You can now choose 'yes' or 'no' in the '$SpecialList' variable. You can edit start points, middle points, and end points, so you can easily make in an unordered list, an ordered list, a div... Anything!
Last edited by Physicsguy; 06-29-2010 at 08:59 PM..
|