search
Homephp教程php手册php实现的遍历文件夹下所有文件,编辑删除

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

Jun 13, 2016 pm 12:20 PM
phpDowncodedeleteFunctionCancopyaccomplishdocumentfolderofeditTraverse

复制代码 代码如下:


/*
遍历文件夹; 功能:(a)可删除文件 (b)可编辑文本,网页文件 (c)可删除文件夹,前提是该文件夹为空 (d)可建立文件,文件夹,修改文件夹名称;
lost63.com原创, 转载请注明出处. 交流QQ:35501547
*/
$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 "$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 '















>> 编辑文件 > 返回
->文件名:'.$_GET['path'].'


';
}else{
echo '











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


';
}
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;
}
?>
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!