automatic folder listing in PHP

Displays a hyperlinked list of all the folders contained in a specified folder. A really simple way to have your own directory browser, just drop the file in the folder as index.php and it will show an index of all folders in the directory on your webspace.

$projectsListIgnore = array ('.','..');
$projectContents = '';
while ($file = readdir($handle)) 
	if (is_dir($file) && !in_array($file,$projectsListIgnore)) 
		$projectContents .= '<li><a href="'.$file.'">'.$file.'</a></li>';

<title>base scripts</title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
html {
	background: #ddd;
body {
	margin: 1em 10%;
	padding: 1em 3em;
	font: 80%/1.4 tahoma, arial, helvetica, lucida sans, sans-serif;
	border: 1px solid #999;
	background: #eee;
	position: relative;
h2 {
	margin: 0.8em 0 0 0;
ul {
	list-style: none;
	margin: 0;
	padding: 0;
a {
	color: #024378;
	font-weight: bold;
	text-decoration: none;
a:hover {
	color: #04569A;
	text-decoration: underline;
<h2>directory of folders</h2>
<ul class="projects"><?php echo $projectContents; ?></ul>

I’ve raided some of the Apache CSS to make it pretty, so credit goes there for the looks.


About Cameron
I'm a final year Computer Science/Information Systems major. Already finished my BA in Politics/Philosophy. I do web and software freelance on the side, while I finish studying. Hoping to be self-employed by the end of my degree, otherwise off into the real-world I go....

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: