Hello,
I am trying to list only .jpg in all sub folders of the directory “MOVIES”. I can get this to work only in the MOVIES directory and not all sub directories. The following is the code I am using.
<?php $folder = "../MOVIES/*/"; // The folder containing the images. $list = array(); // This will hold data for the images found. $valid = array("jpg", "jpeg"); // Images filetypes. // Open the folder and read the files. $dir = opendir($folder); while (($file = readdir($dir)) !== false) { // Make sure the file is an actual file. if (is_file($folder . $file)) { // Check for valid file extensions. if (hasValidExtension($file)) { // Get the image info. // $info->name = $file; // Add the info to the list array. $list[] = $file; } } } // Close the directory. closedir($dir); // Check to make sure a file has a valid extension. function hasValidExtension($file) { global $valid; $dot = strrpos($file, "."); if ($dot === false) { return false; } $ext = substr($file, $dot+1, 4); foreach ($valid as $value) { if ($ext == $value) { return true; } } return false; } ?> <?php foreach($list as $image){ //print the image to browser with anchor tag (Use if you want really :) ) echo ''; } ?>