Hello,
I am new to PHP and have put together the following code just by copying other examples from the web. Now I am stuck and would like to sort and display files alphabetically, and also filter what file type to display or not display. Thank you for your help.
-kkhan5000
[code=php]
<?php
/*
ABOUT:
This snippet will list all the files in the directory of your
choice, truncate the file extension, capitalize the first letter and
put it all in a drop down menu. The script will not list subdirectories so
all you see are the files in your directory.
USAGE:
Change the $dirpath variable the directory you want to list.
*/
//Looks into the directory and returns the files, no subdirectories
//The path to the style directory
$dirpath = ".";
$dh = opendir($dirpat h);
while (false !== ($file = readdir($dh))) {
//Don't list subdirectories
if (!is_dir("$dirp ath/$file"))
{
//Truncate the file extension and capitalize the first letter
echo "<a href='$dirpath/$file'>". htmlspecialchar s(ucfirst(preg_ replace('/\..*$/', '', $file))). "<br />";"</a>";
}
}
closedir($dh);
?>[/code]
I am new to PHP and have put together the following code just by copying other examples from the web. Now I am stuck and would like to sort and display files alphabetically, and also filter what file type to display or not display. Thank you for your help.
-kkhan5000
[code=php]
<?php
/*
ABOUT:
This snippet will list all the files in the directory of your
choice, truncate the file extension, capitalize the first letter and
put it all in a drop down menu. The script will not list subdirectories so
all you see are the files in your directory.
USAGE:
Change the $dirpath variable the directory you want to list.
*/
//Looks into the directory and returns the files, no subdirectories
//The path to the style directory
$dirpath = ".";
$dh = opendir($dirpat h);
while (false !== ($file = readdir($dh))) {
//Don't list subdirectories
if (!is_dir("$dirp ath/$file"))
{
//Truncate the file extension and capitalize the first letter
echo "<a href='$dirpath/$file'>". htmlspecialchar s(ucfirst(preg_ replace('/\..*$/', '', $file))). "<br />";"</a>";
}
}
closedir($dh);
?>[/code]
Comment