PHP implementation of traversing all files in a folder, editing and deleting_PHP tutorial

WBOY
Release: 2016-07-21 15:42:05
Original
1801 people have browsed it

Copy code The code is as follows:

/*
Traverse folders; Function: (a) Deleteable files (b) Editable text, web page files (c) Deleteable folders, provided that the If the folder is empty (d) you can create files, folders, and modify the folder name;
Original by lost63.com, please indicate the source for reprinting. Communication QQ: 35501547
*/
$path=$DOCUMENT_ROOT ;
$path=str_replace("/","\",$path);
//Specify the folder
$path=$path."\";
if($_GET[ 'folder'])
{
$path.=$_GET['folder']."\";
}
//The path of this page will be used when returning below;
$url=$_SERVER['PHP_SELF'];
//If it is a folder, a link will be added;
function folder($path,$str)
{
if(filetype ($path.$str)=="dir")
{
return "$str";
}else{
return $str;
}
}
switch($_GET['action'])
{
case "del";
if($_GET['type']=="file")
{
unlink($_GET['path']);
}else{
rmdir($_GET['path']);
}
echo "";
break;
case "edit";
if($_GET['type']=="file")
{
$file=fopen($_GET['path'],"r");
while(!feof($file))
{
$result.=fgets($file,9999) ;
}
fclose($file);
echo '













';
}else{
echo '
>> Edit file > Return
->File name:'.$_GET['path'].'











< ;/tr>
>> New file > < a href="'.$url.'">Return
->Folder rename:


';
}
break;
case "editsave";
$file=fopen($_GET['path'],"w");
fwrite($file,$_POST['textarea']);
fclose($file);
echo "";
break;
case "addfile";
echo '














>> 新建文件 > 返回
->文件名:


';
break;
case "filesave";
//包含点则建立文件,否则建立文件夹
if(strpos($_POST['filename'],"."))
{
$file=fopen($_POST['filename'],"w");
fwrite($file,$_POST['textarea']);
fclose($file);
}else{
//文件夹若存在则退出,不存在则建立!
if(file_exists($_POST['filename']))
{
exit;
}else{
mkdir($_POST['filename']);
}
}
echo "";
break;
case "dir_rename";
rename($_GET['path'],$_POST['filename']);
echo "";
break;
default:
$s=explode("n",trim(`dir/b/o:gn $path`));
echo '








';
foreach($s as $value)
{
echo '





';
}
echo "
>> 文件管理 > 建立文件 > 返回
文件/文件夹 文件属性 文件大小 操作
'.folder($path,$value).' '.filetype($path.$value).' '.round(filesize($path.$value)/1024).'kb 编辑 | 删除
";
break;
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321015.htmlTechArticle复制代码 代码如下: ?php /* 遍历文件夹; 功能:(a)可删除文件 (b)可编辑文本,网页文件 (c)可删除文件夹,前提是该文件夹为空 (d)可建立文件,文...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template