PHP Scripting

Directory Contents

list all directory contents using PHP

6/22/2020
0 views
php-directory-contents.phpPHP
<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
PHPlist directory contents using PHPdirectory contentsopendirclosedirreaddir

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com