note 46312 deleted from function.glob by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 06 Oct 2004 19:47:32 +0000 |
| Subject: | note 46312 deleted from function.glob by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78094@lists.php.net to get a copy of this message | ||
Note Submitter: jeffrey.brayne at braynepower dot com
----
---
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
}
}