Location: PHPKode > scripts > dir_list > dirlist/dir_list.php
<?php
/*
		dir_list - 	include this in another module to be able to select a file and return to the calling
					module with  $dir_list_return set to the full path of the selected file.
					This version arbitrarily shows drives C,D,E,F,G

*/

	global $path, $path_level;
	


	echo "<br><b>----------------------------- Drives --------------------------------</b>";
	echo "<br><a href=$php_self?file=c:><b>C: drive</a>";
	echo "<br><a href=$php_self?file=d:>D: drive</a>";
	echo "<br><a href=$php_self?file=e:>E: drive</a>";
	echo "<br><a href=$php_self?file=f:>F: drive</a>";
	echo "<br><a href=$php_self?file=g:>G: drive</b></a>";
	echo "<hr>";

//$dir = "e:/kb";

	$dir = $file;
	echo "<br><font size=2 face=arial,verdana>Use the browser back button to return to the previous level";
	echo "<br><br><b>----------------------------- $file --------------------------------</b>";

$php_self = $_SERVER['PHP_SELF'];

	if ($path_level == "") {
		$path_level = 1;
	}
	else {
		$path_level++;
	}
	
	//echo "<br>Starting the called module path_level = $path_level";


// Open a known directory, and proceed to read its contents
	if (is_dir($dir)) {
	    if ($dh = opendir($dir)) {
	    	   $i = 0;
	    	   $filenames = "";
	        while (($file = readdir($dh)) !== false) {
	            //echo "<br><a href=$php_self?file=$file>$file : filetype: " . filetype($dir . $file)."</a>";

			  $filenames[$i] = $file;
			  $i++;
	            //echo "<br><a href=\"$php_self?file=$dir$file\">$bold\"$file\" </b></a>";
	        }
	        closedir($dh);
	        
	        sort ($filenames);
	        $i = 0;

	        while ($filenames[$i] <> "") {
	        	if ($path_level == 1) {
	        		if ($filenames[$i] == ".") {
	        			$wk = ".";
	        		}
	        		elseif ($filenames[$i] == "..") {
	        			$wk = "..";
	        		}
	        		else {
					$wk = $dir.$filenames[$i];
				}
			}
			elseif ($path_level > 1)  {
				if ($filenames[$i] == ".") {
					$wk = ".";
				}
				elseif ($filenames[$i] == "..") {
                    	$wk = "..";
                    }
				else {
					$wk = $dir."/".$filenames[$i];
				}
			}

			if (is_dir($wk)) {
	            	$bold = "<b><img src=dir_list/dir.gif border=0>";
	            }
			  else {
			  	$bold = "<font color=black><img src=dir_list/file.gif border=0>";
			}

			// ------- display the line -----------
			if (($wk == "..") or ($wk == "."))  {
				// don't display anything for these
				//echo "<br><a href=x onclick=history.back()><font size=2 face=arial,verdana>$bold".$filenames[$i]." </font></font></b></a>";
               	$i++;
			}
			else {
             		echo "<br><a href=\"$php_self?file=$wk&path_level=$path_level\"><font size=2 face=arial,verdana>$bold".$filenames[$i]." </font></font></b></a>";
               	$i++;
               }
	 	  }


	    }
	}
	elseif ($file <> "") {
     	echo "<br>File selected = $file";
     	//$wk = $dir.$file;
     	$dir_list_return = $file;
     	return;
     }
     else {
     
     }
	exit;

?>

Return current item: dir_list