note 110394 deleted from function.opendir by danbrown

From: Date: Wed, 17 Oct 2012 21:15:26 +0000
Subject: note 110394 deleted from function.opendir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191359@lists.php.net to get a copy of this message
Note Submitter: Paul Kurenkunnas ---- I added slightly to a function written by Lasse Dalegaard 21-May-2005 12:25 This function now finds and echo's all htm/html/php files from where it is located and all subfolders. <? function getFiles($directory) { // Try to open the directory if($dir = opendir($directory)) { // Create an array for all files found $tmp = Array(); // Add the files while($file = readdir($dir)) { // Make sure the file exists if($file != "." && $file != ".." && $file[0] != '.') { $path = $directory . "/" . $file; // If it's a directory, list all files within it if(is_dir($path)) { $tmp2 = getFiles($path); if(is_array($tmp2)) { $tmp = array_merge($tmp, $tmp2); } } else { $ext = end(explode(".",$path)); if(preg_match("/htm|html|php/",$ext)) array_push($tmp, $path); } } } // Finish off the function closedir($dir); natcasesort($tmp); return $tmp; } } // links to all htm/html/php files $files = getFiles('.'); foreach($files as $f){ echo "<a href='$f'>$f</a><br />"; } ?>

« previous php.notes (#191359) next »