文件目录遍历

<?php
    $num =0;
    $dirname='phpmyadmin';
    $dir_handle=opendir($dirname);
    //将遍历的目录和文件名使用表格的格式输出
    echo '<table border="0" width="600" align="center" cellspacing="0" cellpadding="0">';
    echo '<caption><h2>目录内容</h2></caption>';
    echo '<tr align="left" bgcolor="#cccccc">';
    echo '<th>文件名</th><th>文件大小</th><th>文件类型</th><th>修改时间</th>';

    //使用readdir循环读取目录的内容
    while($file=readdir($dir_handle)){
        //将目录下的文件盒当前目录链接起来,才能在程勋中使用
        $dirfile=$dirname.'/'.$file;

        $bgcolor= $num++%2==0 ? '#ffffff' : '#cccccc';
        echo '<tr bgcolor='.$bgcolor.'>';
        echo '<td>'.$file.'</td>';
            echo '<td>'.filesize($dirfile).'</td>';
            echo '<td>'.filetype($dirfile).'</td>';
            echo '<td>'.date("Y/m/t" , filemtime($dirfile)).'</td>';
            echo '</tr>';
    }
    echo '</table>';
    closedir($dir_handle);
    
?>
posted @ 2013-12-09 02:16  long896130895  阅读(127)  评论(0编辑  收藏  举报