note 18309 rejected from function.readdir by sander
| From: | sander@php.net | Date: | Sat, 06 Apr 2002 19:16:28 +0000 |
| Subject: | note 18309 rejected from function.readdir by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28756@lists.php.net to get a copy of this message | ||
I've made a script which lists dir contents and creates a table with: filename, link, filesize.
here's the code:
<table width="98%" border="1" bgcolor="#333333"
text="#FFFFFF" bordercolor="gray" bordercolordark="black"
style="font-family: Verdana,Arial,Helvetica; font-style: none; font-weight: normal;
text-decoration: none; font-size: 8pt; font-color: white;">
<tr><td align="center"><font
color="DfDfFf">Filename</td>
<td align="center"><font
color='DfDfFf'>Download</font></td>
<td align="center"><font
color="DFDFDf">Filesize</font></td></tr>
<?php
function list_dir_contents($nameofdir) {
$handle=opendir($nameofdir);
while($file_s = readdir($handle)) {
if ($file_s != "." && $file_s != "..") {
$relpath = $nameofdir."/".$file_s;
$file_size = filesize($relpath);
$file_name = substr($file_s, 0, strlen($file_s)-4);
if ($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . " MB"; }
elseif ($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 ." KB";
} else {
$file_size = $file_size . " B";
}
echo "<tr>
<td><font color='7f7f8f'>$file_name</font></td>
<td align=center><a href=
$nameofdir/$file_s><font
color='7f7fCf'>download</font></a></td>
<td align=center><font
color='7f7f8f'>$file_size</font><br></td></tr>";
}}
closedir($handle);
echo "</table>";
}
list_dir_contents('some_directory'); ?>
Please help me!
the result of this script is an unsorted table
the clue is: how to make it sorted by a filename
I was trying with the arrays but I'm a beginner and I don't understand their syntax enough
to write it on my own
so please do not show me just a hint because I wouldn't cope with it.
if anyone could modify it in a way I have written, I would be grateful.
thx in advance