note 59048 deleted from function.readdir by tularis

From: Date: Sun, 13 May 2007 19:02:08 +0000
Subject: note 59048 deleted from function.readdir by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126523@lists.php.net to get a copy of this message
Note Submitter: ES ---- A simple class to read a dir, and display the files. And will automatically sort the files Alphabetically. Very simple indeed. But thought I'd share (one of my first classes aswell) :) <?php class list_dir { var $dir; function open_dir($dir) { $handle = opendir($this->dir); if($handle) { while(false !== ($files = readdir($this->dir))) { if($files != "." && $files != "..") { sort($files); foreach($files as $file) { echo $file."<br>"; } } } } } function close_dir() { closedir($this->dir); } } ?> Usage: <?php $list = new list_dir; $list->open_dir("/path/to/directory/"); $list->close_dir(); ?>

« previous php.notes (#126523) next »