note 41042 added to function.opendir
| From: | Cabal at CnCWorld dot org | Date: | Sun, 28 Mar 2004 11:21:37 +0000 |
| Subject: | note 41042 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67276@lists.php.net to get a copy of this message | ||
I had problems getting it to work because I'm not the best at PHP, but there IS a way to use
opendir to list things in alphabetical order. I'm using it for my university project. All you
have to do is read the filenames into an array, sort the array and then do what you want with the
filenames.... like this....
So that you know what all my variables mean in this - $stats is the folder that it looks in for the
files - for example
?stats=images
would look in the images folder
Obviously you will want to modify it so it fits your needs, but I thought you guys would want this -
especially if your server doesnt have the latest version of php.
===========================
<?php
$i = 0;
$arraycount = 0;
$home="/home/cabal/public_html/b146/admin/$stats";
if ($stats)
{
$dircheck="/home/cabal/public_html/b146/admin/$stats";
if (is_dir($dircheck))
{
if ($handle = opendir($home))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$path = "$home/$file";
$extension = array_pop(explode('.', basename($path)));
$filearray[$i] = $file;
$i++;
}
}
}
closedir($handle);
}
else
{
echo "INCORRECT SELECTION";
}
}
else
{
echo "NOTHING SELECTED";
}
echo " ";
echo("<table width='100%'
border='1'><tr><td><b><font color='#ff0000'>");
echo("$stats : Log File");
echo("</b></font></td><td><font
color='#FF0000'><b>Page
Views</b></font></td></tr>");
sort($filearray);
reset($filearray);
while (list($key, $val) = each($filearray))
{
$includearray = "$home/$filearray[$key]";
echo("<tr><td>");
echo("$val");
echo("</td><td>");
include($includearray);
echo("</td></tr>");
}
echo("</table>");
?>
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41042
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41042&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41042&report=yes
Search -- http://master.php.net/manage/user-notes.php