php开发的管理系统,php开发一个文件管理系统(附代码)

这是一个使用PHP开发的文件管理系统,可以实现目录和文件的在线管理,包括读取、创建、重命名、删除等功能。通过调用`dir.func.php`和`file.func.php`中的函数,如`read_directory()`、`create_dir()`、`rename_dir()`和`del_dir()`等,用户可以进行文件操作。系统还提供了错误处理和操作反馈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

725519e97f8feabde50ef12a8a7c6786.png

效果图

7021dcfa79c8fb404f44478c0744bfed.png<?php

//读取管理项目,并且展示

require_once 'lib/dir.func.php';

require_once 'lib/file.func.php';

date_default_timezone_set("PRC");

error_reporting(E_ALL&~E_NOTICE);

define('WEBROOT','webRoot');

$path=$_REQUEST['path']?$_REQUEST['path']:WEBROOT;

$act=$_REQUEST['act']?$_REQUEST['act']:'';

$dirName=$_REQUEST['dirName']?$_REQUEST['dirName']:'';

$fileName=$_REQUEST['fileName']?$_REQUEST['fileName']:'';

$info=read_directory($path);

// print_r($info);exit;

if(!is_array($info)){

exit("

alert('读取失败');

location.href='index.php';

");

}

//根据不同请求完成不同操作

switch($act){

case 'createDir':

// echo $dirName;exit;

$res=create_dir($path.DIRECTORY_SEPARATOR.$dirName);

if($res===true){

$result['msg']=basename($dirName).'创建成功';

$result['icon']=1;

}else{

$result['msg']=$res;

$result['icon']=2;

}

exit(json_encode($result));

break;

case 'renameDir':

$newName=$path.DIRECTORY_SEPARATOR.$dirName;

$res=rename_dir($fileName,$newName);

if($res===true){

$result['msg']=$fileName.'重命名成功';

$result['icon']=1;

}else{

$result['msg']=$res;

$result['icon']=2;

}

exit(json_encode($result));

break;

case 'delDir':

$res=del_dir($fileName);

if($res===true){

$result['msg']=basename($fileName).'删除成功';

$result['icon']=1;

}else{

$result['msg']=$res;

$result['icon']=2;

}

exit(json_encode($result));

break;

//文件部分

case 'createFile':

$res=create_file($path.DIRECTORY_SEPARATOR.$fileName);

if($res===true){

$result['msg']=basename($fileName).'文件新建成功';

$result['icon']=1;

}else{

$result['msg']=$res;

$result['icon']=2;

}

exit(json_encode($result));

break;

case 'showContents':

$res=show_contents($fileName);

exit($res);

break;

}?>

WEB在线文件管理器

切换导航 首页

搜索

WEB在线文件管理器

WEB在线文件管理器主要是用于管理项目文件,实现在线编辑、修改、删除等操作。

查看更多 »

类型

名称

读/写/执行

访问时间

操作

if(is_array($info['dir'])){

foreach($info['dir'] as $val){ ?>

<?php echo $val['showName'];?><?php echo $val['atime'];?>

打开

&path=<?php echo $path;?>' data-showName='<?php echo $val['showName'];?>'>重命名

剪切

复制

&path=<?php echo $path;?>' data-showName='<?php echo $val['showName'];?>'>删除

}

} ?>

if(is_array($info['file'])){

foreach($info['file'] as $val){ ?>

<?php echo $val['showName'];?><?php echo $val['atime'];?>

查看

编辑

下载

重命名

剪切

复制

删除

}

} ?>

目录函数文件 dir.func.php<?php /**

* 读取目录下的信息返回

* @method read_directory

* @param string $path 目标目录

* @return mixed false|array */function read_directory(string $path){ if(!is_dir($path)){ return false;

} $info=[]; $handle=opendir($path); while(($item=@readdir($handle))!==false){ if($item!='.'&&$item!='..'){ $filePath=$path.DIRECTORY_SEPARATOR.$item; $info['fileName']=$filePath; $info['showName']=$item; $info['readable']=is_readable($filePath)?true:false; $info['writable']=is_writable($filePath)?true:false; $info['executable']=is_executable($filePath)?true:false; $info['atime']=date('Y/m/d H:i:s',fileatime($filePath)); if(is_file($filePath)){ $arr['file'][]=$info;

} if(is_dir($filePath)){ $arr['dir'][]=$info;

}

}

} closedir($handle); return $arr;

}/**

* 创建目录

* @method create_dir

* @param string $path 目录名称

* @return mixed true|string */function create_dir(string $path){ if(is_dir($path)){ return $path.'当前目录已存在同名文件';

} if(!mkdir($path,755,true)){ return $path.'目录创建失败';

} return true;

}/**

* 重命名目录

* @method rename_dir

* @param string $oldName 原目录

* @param string $newName 新名称

* @return mixed string|true */function rename_dir(string $oldName,string $newName){ if(!is_dir($oldName)){ return '原目录不存在';

} if(is_dir($newName)){ return '当前目录下存在同名文件';

} if(!rename($oldName,$newName)){ return '重命名失败';

} return true;

}/**

* 删除目录

* @method del_dir

* @param string $path 目录名称

* @return mixed true|string */function del_dir(string $path){ if(!is_dir($path)){ return '目录不存在';

} $handle=opendir($path); while(($item=@readdir($handle))!==false){ if($item!='.'&&$item!='..'){ $pathName=$path.DIRECTORY_SEPARATOR.$item; if(is_file($pathName)){

@unlink($pathName);

} if(is_dir($pathName)){ $func=__FUNCTION__; $func($pathName);

}

}

} closedir($handle); rmdir($path); return true;

}

文件函数 file.func.php<?php /**

* 创建文件

* @method create_file

* @param string $fileName 文件名称

* @param array $allowExt 允许的文件类型

* @return mixed true|string */function create_file(string $fileName,$allowExt=array('txt','html','php')){ if(is_file($fileName)){ return '当前目录下存在同名文件';

} $ext=strtolower(pathinfo($fileName,PATHINFO_EXTENSION)); if(!in_array($ext,$allowExt)){ return '非法文件类型';

} if(!touch($fileName)){ return '文件创建失败';

} return true;

}/**

* 查看文件内容

* @method show_contents

* @param string $fileName 文件名称

* @param array $allowExt 允许的类型

* @return string 文件内容 */function show_contents(string $fileName,$allowExt=array('jpg','jpeg','png','gif','txt','html','php')){ if(!is_file($fileName)){ return '文件不存在';

} $ext=strtolower(pathinfo($fileName,PATHINFO_EXTENSION)); if(!in_array($ext,$allowExt)){ return '非法文件类型';

} //检测是否是真实图片

if(getimagesize($fileName)){ $res="%7B%24fileName%7D";

}else{ $str=file_get_contents($fileName); if(strlen($str)>0){ $res=highlight_string($str,true);

}else{ $res='文件中没有内容';

}

} return $res;

}

本文来自php中文网,php教程栏目,欢迎学习!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值