PHP 支持中文目录和文件的的遍历:文件编码转换

<?php

header("Content-type:text/html;charset=utf-8");

$num = 0;
$dirname = 'practise';

$dirname = iconv( 'utf-8', 'gb2312',$dirname );

$dir_handle = opendir($dirname);

echo '<table border="0" align="center" width="600" cellspacing="0" cellpadding="0">';
echo '<caption><h2>目录'.$dirname.'下面的内容</h2></caption>';
echo '<tr align="left" background="#ccc">';
echo '<th>文件名</th><th>文件大小</th><th>文件类型</th><th>修改时间</th></tr>';

while($file = readdir($dir_handle)){

    $file1=iconv('gb2312','utf-8',$file);

    $dirFile = $dirname."/".$file;

    $bgcolor = $num++%2==0?'#fff':'#ccc';
    echo '<tr bgcolor='.$bgcolor.'>';
    echo '<td>'.$file1.'</td>';
    echo '<td>'.filesize($dirFile).'</td>';
    echo '<td>'.filetype($dirFile).'</td>';
    echo '<td>'.date("Y-n-t",filemtime($dirFile)).'</td>';
    echo '</tr>';
}

echo '</table>';
closedir($dir_handle);

echo '在<b>'.$dirname.'</b>目录下的子目录和文件共有<b>'.$num.'</b>个';

 

|| 版权声明
作者:冰魄
链接:https://www.bp456.cn/64.html
声明:如无特别声明本文即为原创文章仅代表个人观点,版权归《冰魄博客》所有,欢迎转载,转载
THE END
二维码
海报
PHP 支持中文目录和文件的的遍历:文件编码转换
<?php header("Content-type:text/html;charset=utf-8"); $num = 0; $dirname = 'practise'; $dirname = iconv( 'utf-8', 'gb2312',$dirname ); ……
<<上一篇
下一篇>>