快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

php实现的遍历文件夹下所有文件,编辑删除

遍历文件夹; 功能:(a)可删除文件 (b)可编辑文本,网页文件 (c)可删除文件夹,前提是该文件夹为空 (d)可建立文件,文件夹,修改文件夹名称

<?php  
/*  
遍历文件夹; 功能:(a)可删除文件 (b)可编辑文本,网页文件 (c)可删除文件夹,前提是该文件夹为空 (d)可建立文件,文件夹,修改文件夹名称;  
*/  
$path=$DOCUMENT_ROOT;  
$path=str_replace("/","\\",$path);  
//指定文件夹  
$path=$path."\\";  
if($_GET['folder'])  
{  
$path.=$_GET['folder']."\\";  
}  
//本页面路径,下面传回时将用到;  
$url=$_SERVER['PHP_SELF'];  
//如果是文件夹,将加上链接;  
function folder($path,$str)  
{  
if(filetype($path.$str)=="dir")  
{  
return "<a href=\"?folder=".$_GET['folder']."\\".$str."\">$str</a>";  
}else{  
return $str;  
}  
}  
switch($_GET['action'])  
{  
case "del";  
if($_GET['type']=="file")  
{  
unlink($_GET['path']);  
}else{  
rmdir($_GET['path']);  
}  
echo "<script type=\"text/javascript\">alert('恭喜,删除成功!');location.href=\"".$url."\";</script>";  
break;  
case "edit";  
if($_GET['type']=="file")  
{  
$file=fopen($_GET['path'],"r");  
while(!feof($file))  
{  
$result.=fgets($file,9999);  
}  
fclose($file);  
echo '<form name="form1" method="post" action="?action=editsave&path='.$_GET['path'].'&type='.$_GET['type'].'">  
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">  
<tr>  
<td height="25" bgcolor="#99CC00">>><strong> 编辑文件</strong> > <a href="'.$url.'">返回</a></td>  
</tr>  
<tr>  
<td height="25" align="left" bgcolor="#FFFFCC">->文件名:'.$_GET['path'].'</td>  
</tr>  
<tr>  
<td align="center" bgcolor="#FFFFFF"><textarea name="textarea" cols="135" rows="20">'.$result.'</textarea></td>  
</tr>  
<tr>  
<td align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="提交">  
<input type="reset" name="Submit2" value="重置"></td>  
</tr>  
</table>  
</form>';  
}else{  
echo '<form name="form1" method="post" action="?action=dir_rename&path='.$_GET['path'].'&type='.$_GET['type'].'">  
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">  
<tr>  
<td height="25" bgcolor="#99CC00">>><strong> 新建文件</strong> > <a href="'.$url.'">返回</a></td>  
</tr>  
<tr>  
<td height="25" align="left" bgcolor="#FFFFCC">->文件夹更名:  
<input name="filename" type="text" value="'.$_GET['path'].'" size="50"></td>  
</tr>  
<tr>  
<td align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="提交">  
<input type="reset" name="Submit2" value="重置"></td>  
</tr>  
</table>  
</form>';  
}  
break;  
case "editsave";  
$file=fopen($_GET['path'],"w");  

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论