php代码:实现当前目录文件列表列出

前端之家收集整理的这篇文章主要介绍了php代码:实现当前目录文件列表列出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

  建站学院(LieHuo.Net)网络编程 关于PHP实现列出当前文件列表的方法,网上有很多,近日liehuo.net的小编综合了网上的一些资料, 改写了一下,感觉这是最佳的方法,特别将代码公布出来。

以下为引用的内容

<?PHP
function tree($directory)
{
echo date(”Y-m-d H:i:s”);
$i=0;
$mydir=dir($directory);
echo “<ul>”;
while($file=$mydir->read() AND $i<5)
{
if((is_dir(”$directory”)) AND ($file!=”.”) AND ($file!=”..”))
{
$filetime=date(”Y-m-d H:i:s”,filectime($file));
//encode spaces
$file =  rawurlencode($file);
// convert the + (this is one result from the function rawurlencode) in %20
$url = str_replace(’+’,‘%20′,$file);
echo “<li><font color=”#ff00cc”><a href=’”.$url.”‘>”.$url.”</a></font>  $filetime<br/></li>”;
$i+=1;
}
}
echo “</ul>”;
$mydir->close();
}

tree(”.”);  // 列出当前目录
?>

猜你在找的PHP相关文章