Sorting files in a directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greetings,

I have some code that opens a directory and displays the files. I want to
display the files in Alphabetical order.

I know this code does not work, but I was curious if someone can take a look
and tell me what is wrong? Thank you so much.

<form name="select_page" method="post" action="">
            <?php

// set pattern
$pattern = ".html*|.php*";

// open directory and parse file list
if (is_dir("files/"))
{
if ($dh = opendir("files/"))

{
echo "<select name=\"file\" size=\"8\">";
//echo "<option value=\"$file\" selected>$file</option>";

// iterate over file list
while (($file = readdir($dh)) !== false)
{
// if filename matches search pattern, print it
if (ereg($pattern, $file))
   if(strpos($file,'.')>0)
   
//  if ($filename = str_replace('.html','',$filename))

{
$file_array = array($file);
sort ($file_array);

foreach($file_array as $key => $value) {
echo "<option value=\"$value\">".$value."</option>";
}
}
}
echo "</select>";

// close directory
closedir($dh);
}
}
?>
            <p>
              <input type="submit" name="Submit" value="Submit">
            </p>
        </form>

--
Steve Marquez

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux