note 110394 added to function.opendir

From: Date: Wed, 17 Oct 2012 21:07:00 +0000
Subject: note 110394 added to function.opendir
Groups: php.notes 
Request: Send a blank email to php-notes+get-191358@lists.php.net to get a copy of this message
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 />"; } ?> ---- Server IP: 80.64.47.13 Probable Submitter: 67.187.232.125 ---- Manual Page -- http://www.php.net/manual/en/function.opendir.php Edit -- https://master.php.net/note/edit/110394 Del: integrated -- https://master.php.net/note/delete/110394/integrated Del: useless -- https://master.php.net/note/delete/110394/useless Del: bad code -- https://master.php.net/note/delete/110394/bad+code Del: spam -- https://master.php.net/note/delete/110394/spam Del: non-english -- https://master.php.net/note/delete/110394/non-english Del: in docs -- https://master.php.net/note/delete/110394/in+docs Del: other reasons-- https://master.php.net/note/delete/110394 Reject -- https://master.php.net/note/reject/110394 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191358) next »