<?
// 查看指定文件夹的文件
$fileList = array();
function visitFile($path)
{
global $fileList;
$path = str_replace("\\", "https://www.jb51.net/", $path);
$fdir = dir($path);
while (($file = $fdir->read()) !== false)
{
if($file == '.' || $file == '..'){ continue; }
$pathSub = preg_replace("*/{2,}*", "https://www.jb51.net/", $path."https://www.jb51.net/".$file); // 替换多个反斜杠
$fileList[] = is_dir($pathSub) ? $pathSub."https://www.jb51.net/" : $pathSub;
if(is_dir($pathSub)){ visitFile($pathSub); }
}
$fdir->close();
return $fileList;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<form method="get">
<?
$path = str_replace("\\", "https://www.jb51.net/", $path);
$path = preg_replace("*/{2,}*", "https://www.jb51.net/", $path);
?>
路径:<input type="text" value="<?=$path;?>"/><br>
<li>磁盘根目录 /</li>
<li>网络本地 ./phpMyAdmin</li>
<li>本地磁盘 file://C: 或者 C:</li>
<br>
<input type="submit" value="view" />
<input type="submit" value="delete" />
</form>
<?
if(!empty($path)){
$path = preg_replace("*/{2,}*", "https://www.jb51.net/", $path);
$files = visitFile($path);
switch(strtolower($_GET["action"]))
{
case "view":
foreach($files as $key => $value)
{
printf("No.%4d·%s<br>\r\n", $key+1, $value);
}
break;
case "delete":
$faileFiles = array();
foreach(array_reverse($files) as $value)
{
if(!unlink($value))
{
array_push($faileFiles, $value);
}
}
if(!unlink($path)) { array_push($faileFiles, $path); }
if(count($faileFiles) > 0)
{
printf("<br><br>删除失败文件(%d):<p>\r\n", count($faileFiles));
foreach( $faileFiles as $key => $value)
{
printf("No.%4d·%s<br>\r\n", $key+1, $value);
}
}
break;
}
}
?>
php visitFile()遍历指定文件夹函数
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/abf1557c14a85a3449ac05e63ab25d1a.html