note 19620 rejected from function.readdir by sander
| From: | sander@php.net | Date: | Sat, 06 Apr 2002 19:16:58 +0000 |
| Subject: | note 19620 rejected from function.readdir by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28760@lists.php.net to get a copy of this message | ||
<?
$imagedir="path/to/dir";
$today=time();
$limit=60*60*24*7; //1 week
$dp=opendir($imagedir);
?>
<table border='0' cellpadding='5' cellspacing='0'
width='580'>
<tr align='center'>
<?
$count=0;
while ($file=readdir($dp)) {
if (($file != ".") && ($file != ".."))
$dirinfo[count($dirinfo)]=$file;
}
sort($dirinfo);
//read directory and sort
//---------------------------------------------
for ($i = 0; $i<count($dirinfo); $i++) {
$fileinfo[size]=filesize($dirinfo[$i]);
$fileinfo[image]=getimagesize($dirinfo[$i]);
$fileinfo[stats]=filemtime($dirinfo[$i]);
if ($fileinfo[size]<1024)
$fileinfo[size] .= " B";
else if ($fileinfo[size]>1024 && $fileinfo[size]<1024*1024)
$fileinfo[size]=sprintf("%0.1f KB", $fileinfo[size]/1024);
else
$fileinfo[size]=sprintf("%0.2f MB", $fileinfo[size]/(1024*1024));
if ($fileinfo[image][0] > 150) {
$width=150;
$height=(int)($width*$fileinfo[image][1]/$fileinfo[image][0]);
}
else {
$width=$fileinfo[image][0];
$height=$fileinfo[image][1];
}
if (($today - $fileinfo[stats]) < $limit)
$fileinfo[stats]=date("Y/m/d", $fileinfo[stats])." <img
src='icon_new.gif' border='0'>"; //new icon
?>
<td valign='top'>
<img src='<?=$imagedir."/".$dirinfo[$i]?>' border='0'
width='<?=$width?>' height='<?=$height?>'>
<?=$dirinfo[$i]?>
<?=$fileinfo[image][0]?>x<?=$fileinfo[image][1]?>,
<?=$fileinfo[image][bits]?> bit, <?=$fileinfo[size]?>
<?=$fileinfo[stats]?></a>
</td>
<?
$count++;
if ($count == 3) {
$count=0;
?>
</tr>
<tr align='center'>
<?
}
}
?>
</tr>
</table>