TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-17-2010, 08:24 PM   #1 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Default Getting Extra Files Shown In Folder???

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?
Attached Thumbnails
getting-extra-files-shown-folder-dropdown.png  getting-extra-files-shown-folder-folder.png  
gillweb is offline  
Reply With Quote
Old 11-17-2010, 09:12 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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)).
Salathe is offline  
Reply With Quote
Old 11-17-2010, 09:21 PM   #3 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Default

Awesome thank you! 1 more thing... anyway of sorting the files in alpha order?
gillweb is offline  
Reply With Quote
Old 11-17-2010, 10:47 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Determine if this folder is the last level within that folder? Peuplarchie General 1 03-01-2010 04:27 AM
Check if specific folder contains files, folders, both or none ? Peuplarchie General 1 02-27-2010 04:36 AM
How use PHP to read image files from a folder and display them in Flex 3 tilelist. chunL Absolute Beginners 12 07-13-2009 01:49 AM
Adding Images to a database from a folder Rendair Advanced PHP Programming 3 01-13-2008 07:40 PM


All times are GMT. The time now is 08:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design