note 46312 added to function.glob
| From: | jeffrey dot brayneatbraynepowerdotcom at osu1 dot php dot net | Date: | Wed, 06 Oct 2004 18:45:58 +0000 |
| Subject: | note 46312 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78090@lists.php.net to get a copy of this message | ||
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
}
}
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46312
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46312&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46312&report=yes
Search -- http://master.php.net/manage/user-notes.php