note 86975 deleted from function.readdir by danbrown

From: Date: Thu, 13 Nov 2008 15:17:00 +0000
Subject: note 86975 deleted from function.readdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146493@lists.php.net to get a copy of this message
Note Submitter: andy at mail310 dot com ---- I'm sorry, but i think it's much easyer to do the following to prevent a certain extension form being red or opened inside the directory. <?php $handler = opendir("your/path/here/"); while ($file = readdir($handler)) { // if $file isn't this directory or its parent, and it's not a PHP file if ($file != '.' && $file != '..' && strrchr($file, '.')!= '.php') { //Do your stuff here } } ?> what strrchr does is it reads to the last . in the file name and returns the rest of the string (after the dot, including the dot) so if you say don't want jpg files to show, simply add && strrchr($file, '.')!= '.jpg' and well, you get the gist...

« previous php.notes (#146493) next »