Get Website Learn Coding Tech Story

PHP Programming Examples

<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

Learn more about opendir, readdir and closedir