Directory Contents

<html>
	<head>
		<title>Listing the Contents of a Directory</title>
	</head>
	<body>
		<ul>
			<?php
				/* Directory name */
				$dirname = "test";
				
				/* Open directory handle */
				$dh = opendir( $dirname );
				
				/* Read directory */
				while(!is_bool($file = readdir($dh))) {
					
					/* List all directory and files */
  					if(is_dir( "$dirname/$file" ))
    					echo "<li>".$file." <small>(directory)</small></li>";
  					else
  						echo "<li>".$file."</li>";
				}
				
				/* Close directory handle */
				closedir($dh);
			?>
		</ul>
	</body>
</html>




/* Output */
contact _form.php
.. (directory)
a.php
ligthbox.html
file upload (directory)
abc.php
autocomplete (directory)
imageflow.packed.css
time.php
. (directory)
compress img.php

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!