note 19620 added to function.readdir
| From: | webmaster at php2 dot chek dot com | Date: | Wed, 06 Mar 2002 07:45:44 +0000 |
| Subject: | note 19620 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27394@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>
--
http://www.php.net/manual/en/function.readdir.php
http://master.php.net/manage/user-notes.php?action=edit+19620
http://master.php.net/manage/user-notes.php?action=delete+19620
http://master.php.net/manage/user-notes.php?action=reject+19620