Jump to content

Listing Directory Contents


connorm

Recommended Posts

Hey guys this is my first post,

I'm trying to get a script working to list the directory contents.  You can see it here: http://conartistdesign.com/sandbox/dir.php

As you can see, it works in the "sandbox" directory. But when you click on a a directory it is supposed to ten show you the directory contents of that directory without actually taking you there. Also the links for the files do not all work correctly. I have atried for a couple hours but I cannot seem to be able to find out what I'm doing wrong.

 

Here is The Code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Directory Contents</title>

<link href="dirstyles.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<div id="wrapper">

<?php

//directories

$path = getcwd() . "/" . $_GET['id'];

$dir_handle = opendir($path);

echo "<h1>Directory Listing of $path</h1>";

echo "Directories<br />";

echo "<ul>";

while ( $dir = readdir($dir_handle) ) {

if ( is_dir($dir) && ($dir != "." && $dir != "..")) {

echo "<li><a href=\"dir.php?id=$dir\">$dir</a></li>";

}

}

echo "</ul>";

closedir($dir_handle);

 

//files

echo "Files<br />";

echo "<ul>";

$file_handle = opendir($path);

while ( $file = readdir($file_handle) ) {

if ( is_file($file) && ($file != "error_log")) {

echo "<li><a href=\"" . $_GET['id'] . "/" .  "$file\">$file</a></li>";

}

}

closedir($file_handle);

?>

</div>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/152085-listing-directory-contents/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.