View Single Post
Old 02-23-2009, 08:41 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I would say use glob, unless there is a particular reason you're using opendir. The glob function will automatically parse the directory in alphabetical order, and so I've reversed it in the example below to show you how it works to order.

php Code:
/* Directory with or without trailing slash as rtrim will remove it anyway. */
$szDir = './app/controllers/';

/* Glob acquires all the files for us with the extension specified (WMV). */
$aFiles = glob(rtrim($szDir, '/') . '/*.wmv');

/* Glob already outputs in alphabetical order, so reverse to show it's working. */
$aFiles = array_reverse($aFiles);

foreach ($aFiles as $szFile)
{
    /* Echo the radio buttons using the relevant data. */
    printf
    (
        '<input type="radio" name="trailer" value="%s" /><font color="white">%s</font><br />',
        pathinfo($szFile, PATHINFO_FILENAME), basename($szFile)
    );
}
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote