TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Getting Extra Files Shown In Folder??? (http://www.talkphp.com/general/5632-getting-extra-files-shown-folder.html)

gillweb 11-17-2010 08:24 PM

Getting Extra Files Shown In Folder???
 
2 Attachment(s)
I am using this code in a PHP script to list all the files in a folder.
PHP Code:

                <select name="menu1">
                    <?php 
                $dir 
"/img/logos"

                
// Open a known directory, and proceed to read its contents 
                
if (is_dir($dir)) { 
                   if (
$dh opendir($dir)) { 
                       while ((
$file readdir($dh)) !== false) { 
                           print 
"<option value=\"{$file}\">{$file}</option>\n"
                       } 
                       
closedir($dh); 
                   } 
                } 
                
?>
                  </select>

Works great EXCEPT i'm getting extra files being read in the folder and showing just as dots?
You can see from this screen that i have no other files in the directory but this screen shows the extra in my dropdown menu?

Any help?

Salathe 11-17-2010 09:12 PM

See example #2 in the manual (http://php.net/readdir) for how to strip the "dot files". As for why they're there at all, they are standard items in directory listings which represent the current (.) and parent (..) folders (see http://en.wikipedia.org/wiki/Path_(computing)).

gillweb 11-17-2010 09:21 PM

Awesome thank you! 1 more thing... anyway of sorting the files in alpha order?

Salathe 11-17-2010 10:47 PM

Two similar ideas:
  1. First put the files into an array using opendir/readdir/closedir, then sort that array with one of the array sorting functions.
  2. or, use the glob() function to retrieve an array of the files sorted in alphabetical order.


All times are GMT. The time now is 10:18 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0