note 99152 added to function.glob
| From: | noreally at thankyou2010 dot com | Date: | Fri, 30 Jul 2010 15:26:05 +0000 |
| Subject: | note 99152 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171235@lists.php.net to get a copy of this message | ||
If you need to retrieve files that are in another folder than your PHP script and want to use glob
because you think it's shorter than the oldfashioned readdir loop, forget about it.
Let's say your script is in the base folder of your webspace and you have a folder called
"myfolder" in it, from which you want to retrieve all files into an array. The result will
be something like:
myfolder/this.txt
myfolder/that.txt
myfolder/something.txt
myfolder/blah.txt
As you can see, you will have to write an additional loop to get rid of "myfolder/" and
have the filenames alone, so you might as well use:
if ($foldername = opendir("myfolder")) {
while (false !== ($filename = readdir($foldername))) {
if ($filename != "." && $filename != "..") {
$files[] = $filename;
}
}
closedir($foldername);
}
Which gives you:
this.txt
that.txt
something.txt
blah.txt
----
Server IP: 194.153.94.10
Probable Submitter: 188.60.132.144
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- https://master.php.net/note/edit/99152
Del: integrated -- https://master.php.net/note/delete/99152/integrated
Del: useless -- https://master.php.net/note/delete/99152/useless
Del: bad code -- https://master.php.net/note/delete/99152/bad+code
Del: spam -- https://master.php.net/note/delete/99152/spam
Del: non-english -- https://master.php.net/note/delete/99152/non-english
Del: in docs -- https://master.php.net/note/delete/99152/in+docs
Del: other reasons-- https://master.php.net/note/delete/99152
Reject -- https://master.php.net/note/reject/99152
Search -- https://master.php.net/manage/user-notes.php