■サンプルソース
<body>
<table border="1">
<tr>
<th>ファイル名</th>
<th>サイズ</th>
<th>最終アクセス日</th>
<th>最終更新日</th>
</tr>
<?php
clearstatcache();
$place = './dat/';
$dir = opendir($place);
while($file = readdir($dir)){
//if($file != '..' && $file != '.'){
print('<tr>');
print('<td><a href="' . $place . $file . '">' . $file . '</a></td>');
print('<td>' . filesize($place . $file) . '</td>');
print('<td>' . date('Y/m/d H:i:s', fileatime($place . $file)) . '</td>');
print('<td>' . date('Y/m/d H:i:s', filemtime($place . $file)) . '</td>');
print('</tr>');
//}
}
closedir($dir);
?>
</table>
</body>
■表示例
ファイル名 |
サイズ |
最終アクセス日 |
最終更新日 |
. |
512 |
2008/01/10 16:24:38 |
2008/01/10 16:03:10 |
.. |
512 |
2008/01/10 16:24:37 |
2008/01/10 16:03:10 |
1.txt |
0 |
2008/01/10 16:03:10 |
2008/01/10 16:17:01 |
2.txt |
4 |
2008/01/10 16:03:10 |
2008/01/10 16:17:42 |
3.txt |
0 |
2008/01/10 16:03:10 |
2008/01/10 16:17:01 |
4.txt |
0 |
2008/01/10 16:03:10 |
2008/01/10 16:17:01 |
■関数の解説
- int filesize(string filename)
ファイルサイズ(バイト)を返す
- int fileatime(string filename)
ファイルの最終アクセス日時(タイムスタンプ)を返す
- int filemtime(string filename)
ファイルの最終更新日時(タイムスタンプ)を返す
- 上記string filenameには実行したPHPファイルからのパスを文字列として与える事
■注意
- ユーザーにディレクトリを指定させる場合は、サーバー上の非公開領域閲覧(ディレクトリトラバーサル)などに注意しましょう。