note 99152 rejected from function.glob by didou

From: Date: Tue, 05 Oct 2010 12:38:42 +0000
Subject: note 99152 rejected from function.glob by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172969@lists.php.net to get a copy of this message
Note Submitter: noreally at thankyou2010 dot com ---- 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: <?php 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

« previous php.notes (#172969) next »