<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>洋子的文件-分享</title> <style type="text/css"> .bg{background-color:#009BCE;} .all{background-color:#E8E8E8;} </style> </head> <body style="font-size:30px" > <div class="all"> <?php $path='./'; $self=basename($PHP_SELF); if($_GET['path']!='') $path=$_GET['path']; else $_GET['path']='./'; #下面这段代码来源网络 ?> <?php /** * Goofy 2011-11-30 * getDir()去文件夹列表,getFile()去对应文件夹下面的文件列表,二者的区别在于判断有没有“.”后缀的文件,其他都一样 */ //获取文件目录列表 function getDir($dir) { if (false != ($handle = opendir ( $dir ))) { $i=0; while ( false !== ($file = readdir ( $handle )) ) { //去掉"“.”、“..”以及带“.xxx”后缀的文件 if ($file != "." && $file != ".."&&!strpos($file,".")) { if(($i%2)==0) echo '<div class="bg" >'.' <a href="'.$self.'?path='.$_GET['path'].'/'.$file.'">'.$file.'</a></div>'; else echo ' <a href="'.$self.'?path='.$_GET['path'].'/'.$file.'">'.$file.'</a>'; $i++; } } //关闭句柄 closedir ( $handle ); } return $dirArray; } //获取文件列表 function getFile($dir) { if (false != ($handle = opendir ( $dir ))) { $i=0; while ( false !== ($file = readdir ( $handle )) ) { //去掉"“.”、“..”以及带“.xxx”后缀的文件 if ($file != "." && $file != "LOST.DIR" && $file != ".."&&strpos($file,".")) { $size=filesize($_GET['path'].'/'.$file); if($size>=1024 && $size<1048576) { $size/=1024; $b='KB'; } else if($size>=1048576) { $size/=1048576; $b='MB'; } else $b='B'; $size=round($size, 2); if($i%2==0) echo '<div class="bg"><font color=#FF0000>'.$size.$b.'</font> <a href="./'.$_GET['path'].'/'.$file.'">'.$file.'</a></div>'; else echo '<font color=#FF0000>'.$size.$b.'</font> <a href="./'.$_GET['path'].'/'.$file.'">'.$file.'</a>'; if($i==255){ break; } $i++; } } //关闭句柄 closedir ( $handle ); } } //调用方法getDir("./dir")…… ?> =====目录列表===== <br/><a href="<?php echo $self.'?path='.dirname($_GET['path']).'"><font color=FF0000>↑向上↑</font></a> '; ?>当前目录: <?php echo $path; getDir($path); ?> <br/><br/>=====文件列表=====<br/> <?php getFile($path); ?> <br/><br/>=====BY:洋子===== </div> </body> </html>
很久以前写的,不知道该能不能用,,,