All pastes #957636 Raw Edit

Anonymous

public text v1 · immutable
#957636 ·published 2008-03-26 02:42 UTC
rendered paste body
<html>
	<head>
		<title>Lab 9 - Ryan Small</title>
	</head>

	<body>

		<p>Currently working in the <?php echo getcwd();?> directory.</p>
		<pre>
		<?php

			$rootdir;
			$tabcount = 0;

			function readdirectory($directstring)
			{
				global $rootdir, $tabcount;
				if($directstring =="")
				{
					$directstring = getcwd();
				}
				//$dirhandle is the variable that stores which directory to read from
				//This statement acquires the current working directory to read from and places it in $dirhandle
				$dirhandle = opendir($directstring);

				//readdir() returns a false value when it can't read a directory, so this statement will continue to
				//loop until that time when readdir() returns false. That will happen when it finishes reading the directory
				//or if it can't read it at all.
				//$directory is the variable that is used to hold the name of what it readdir() is reading.
				while( false!== ($directory = readdir($dirhandle)))
				{
					//this if statement checks to see if the file that was read was a directory or a file
					if ( is_dir($directory))
					{
						//if it was a directory, it parses through and ignores the directories "." and ".."
						//"." is a self reference, and ".." is a reference to the parent directory. It ignores
						//these because there's no use in displaying them.
						if ( $directory != "." && $directory != ".." )
						{	
							//Now we start displaying the names of the directories that were found with readdir()	
							for($i=0; $i<$tabcount; $i++) echo "\t";			
							echo $directory . ":<br />";
	
							$directstring = getcwd() . "/" . "$directory";
							chdir($directstring);

							$temp = $rootdir;
							$rootdir .= $directory . "/";
							$tabcount++;
							readdirectory($directstring);
							$rootdir = $temp;
						}
					}
					elseif(is_file($directory))
					{
						//Displays the files for linking
						for( $i=0; $i < $tabcount; $i++) echo "\t";
						echo "<a href='{$rootdir}{$directory}'>{$directory}</a><br />";
					}	
				}
				$tabcount--;
				chdir("..");
				closedir($directstring);
			}

			echo "<br />Directories:<br />";
			readdirectory($directstring);
						
		?>
		</pre>

	</body>
</html>