All pastes #951133 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-21 01:39 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
			echo "<br />Directories:<br />";
			
			//$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(getcwd());

			//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) == true)
				{
					//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()				
						echo "\t" . $directory . ":<br />";

						//This creates a new instance of $dirhandle to read into the directories that were listed
						//above
						$dirhandle2 = opendir($directory);

						//As was the case above, we start reading the directory again until such time as readdir()
						//returns a false value
						while( false!== ($file=readdir($dirhandle2)))
						{
							//Once again we ignore the "." and ".." directory references.
							if ( $file != "." && $file != ".." )
							{
								//This displays a link to the files found (.php or .html most likely) that can
								//be clicked through to access.
								echo "\t\t<a href=" . $directory . "/" . $file . ">" . $file . "</a><br />";
							}
						}
					}
				}

				//Now we look through the files that were in the main directory, and display thoses.
				elseif(is_file($directory) == true)
				{
					//Displays the files for linking
					echo "\t<a href=" . $directory . ">" . $directory . "</a><br />";
				}
				
				
			}
			
		?>
		</pre>

	</body>
</html>