note 86975 added to function.readdir

From: Date: Thu, 13 Nov 2008 05:54:38 +0000
Subject: note 86975 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-146466@lists.php.net to get a copy of this message
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... ---- Server IP: 209.41.74.194 Probable Submitter: 208.57.91.240 ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- https://master.php.net/note/edit/86975 Del: integrated -- https://master.php.net/note/delete/86975/integrated Del: useless -- https://master.php.net/note/delete/86975/useless Del: bad code -- https://master.php.net/note/delete/86975/bad+code Del: spam -- https://master.php.net/note/delete/86975/spam Del: non-english -- https://master.php.net/note/delete/86975/non-english Del: in docs -- https://master.php.net/note/delete/86975/in+docs Del: other reasons-- https://master.php.net/note/delete/86975 Reject -- https://master.php.net/note/reject/86975 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146466) next »