note 46312 modified in function.glob by tularis

From: Date: Wed, 06 Oct 2004 19:47:12 +0000
Subject: note 46312 modified in function.glob by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78092@lists.php.net to get a copy of this message
--- Editor's note: It's easier to use basename() for this than what is described here. --- To extract the file name from the file path when trying to loop through files in a directory, I found this to be a relatively painless way to loop: $imgdir="./path/to/imgs/"; $imgs = Array(); $imgs = glob($imgdir."/{*.jpg,*.JPG}",GLOB_BRACE); if($imgs!=""){ //make sure dir isn't empty foreach ($imgs as $filepath) { $file = substr($filepath,(strrpos($filepath, "/")+1)); //do something with the files } } --was-- To extract the file name from the file path when trying to loop through files in a directory, I found this to be a relatively painless way to loop: $imgdir="./path/to/imgs/"; $imgs = Array(); $imgs = glob($imgdir."/{*.jpg,*.JPG}",GLOB_BRACE); if($imgs!=""){ //make sure dir isn't empty foreach ($imgs as $filepath) { $file = substr($filepath,(strrpos($filepath, "/")+1)); //do something with the files } } http://php.net/manual/en/function.glob.php

« previous php.notes (#78092) next »