Listing the contents of a directory

Listing the contents of a directory

../images contains the following files and folders:

 

CODE FOLLOWS

<?php
// Include the header file (assumed to contain common HTML and styles)
include('includes/header.php');
?>


    <!DOCTYPE html>
<html lang="en">
<head>
    <title>Listing the contents of a directory</title>
    <link rel="stylesheet" type="text/css" href="css/common.css" />
</head>
<body>
<h1>Listing the contents of a directory</h1>

<?php

$dirPath 
"../images";
if ( !( 
$handle opendir$dirPath ) ) ) die( "Cannot open the directory." );

?>

<p><?php echo $dirPath ?> contains the following files and folders:</p>
<ul>
    <?php

    
while ( $file readdir$handle ) ) {
        if ( 
$file != "." && $file != ".." ) echo "<li>$file</li>";
    }

    
closedir$handle );

    
?>

</ul>
</body>
</html>

<?php
// Include the footer file (assumed to contain closing HTML and scripts)
include('includes/footer.php');
?>