php实现的遍历文件夹下所有文件,编辑删除_php技巧
/*
遍历文件夹; 功能:(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 '';
}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 '
>> 文件管理 > 建立文件 > 返回 | |||
文件/文件夹 | 文件属性 | 文件大小 | 操作 |
'.folder($path,$value).' | '.filetype($path.$value).' | '.round(filesize($path.$value)/1024).'kb | 编辑 | 删除 |
break;
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
