مثلا فایل simple.php
<?php
$action = isset($_GET['action']) ? $_GET['action'] : '';
$path = isset($_REQUEST['path']) ? $_REQUEST['path'] : '';
$title = $content = '';
switch($action){
case 'batchDel':
$title = '删除选中文件';
$content = '';
if(isset($_POST['files'])){
foreach($_POST['files'] as $v){
if(file_exists($v)){
if(unlink($v)){
$content .= '';
}else{
$content .= '';
}
}else{
$content .= '';
}
}
$content .= '
文件名 |
操作 |
'.$v.' |
删除成功 |
'.$v.' |
删除失败 |
'.$v.' |
删除成功 |
';
}
break;
case 'del':
$title = '删除文件';
$content = '
文件名 |
操作 |
'.$path.' |
';
if($path){
if(file_exists($path)){
if(unlink($path)){
$content .= 'Success';
}else{
$content .= 'Fail ';
}
}else{
$content .= 'Success';
}
}
$content .= ' |
';
break;
case 'edit':
$title = '查看/编辑 代码';
$code = isset($_POST['code']) ? $_POST['code'] : '';
if($code){
if(file_exists($path)){
$result = file_put_contents($path, $code);
if($result){
$content = '编辑成功';
}else{
chmod($path, 0644);
$temp = file_put_contents($path, $code);
if($temp){
$content = '修改权限后,编辑成功。';
}else{
$content = '修改权限后,编辑也失败。';
}
}
}else{
$content = '文件不存在,编辑失败。';
}
}else{
$content = '
内容
'.htmlspecialchars(file_get_contents(htmlspecialchars($path))).'
';
}
break;
default:
$root = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '';
$dir = __DIR__;
if($path){$dir = $path;}
$title = $dir;
$content = '';
foreach(hardScandir($dir) as $value){
$fullPath = str_replace('//', '/', $dir."/".$value);
if($value != '.' && $value != '..' && is_dir($fullPath)){
$content .= '';
}
}
foreach(hardScandir($dir) as $value){
$fullPath = str_replace('//', '/', $dir."/".$value);
if($value != '.' && $value != '..' && !is_dir($fullPath)){
$content .= '';
}
}
$content .= '
|
文件名 |
权限 |
创建时间 |
编辑时间 |
访问时间 |
大小 |
操作 |
|
'.$fullPath.' |
'.substr(sprintf('%o', fileperms($fullPath)), -4).' |
'.date("Y-m-d H:i:s", filectime($fullPath)).' |
'.date("Y-m-d H:i:s", filemtime($fullPath)).' |
'.date("Y-m-d H:i:s", fileatime($fullPath)).' |
文件夹 |
|
|
'.$fullPath.' |
'.substr(sprintf('%o', fileperms($fullPath)), -4).' |
'.date("Y-m-d H:i:s", filectime($fullPath)).' |
'.date("Y-m-d H:i:s", filemtime($fullPath)).' |
'.date("Y-m-d H:i:s", fileatime($fullPath)).' |
'.round(filesize($fullPath) / 1024, 2).' Kb |
删除 |
全选 |
';
break;
}
function hardScandir($dir){
if(function_exists("scandir")){
return scandir($dir);
}else{
$dh = opendir($dir);
while(false !== ($filename = readdir($dh)))
$files[] = $filename;
return $files;
}
}
function escape($uri){
return str_replace('%2F', '/', rawurlencode($uri));
}?>
<!doctype html>
Simple File Manage Design by index.php
body{font-size:16px;color:#000;font-sans-serif: system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";}a{text-decoration:none;}*{padding:0;margin:0;list-style:none;}.fa{padding-right:10px;}.submit{background-color:#1e9fff;vertical-align:middle;
height: 38px;line-height: 38px;text-align:center;padding:0 18px;color:#FFF;border-radius:5px;cursor: pointer;}.border-none{border:none !important;}
.container{width: 95%;margin: 0 auto;}
fieldset{display: block;margin-inline-start: 2px;margin-inline-end: 2px;padding-block-start: 0.35em;padding-inline-start: 0.75em;padding-inline-end: 0.75em;padding-block-end: 0.625em;min-inline-size: min-content;border-width: 2px;border-style: groove;border-color: rgb(192, 192, 192);border-image: initial;}
legend{display:block;padding-inline-start: 2px;padding-inline-end: 2px;border-width: initial;border-style: none;border-color: initial;border-image: initial;margin-left: 20px;
padding:0 10px;font-size:20px;font-weight:300;}
.field-title{margin:27px 0 20px;border-width:0;border-top-width:1px;}
.table{border-collapse:collapse;border-spacing:0;overflow:scroll;width:100%;}
.table td{word-break:break-all;max-width:300px;background-color:#FFF;}
.table th, .table td{border: 1px solid #ddd;padding:8px;}
.table tbody > tr:hover{background-color:#ccffcc;}
.table tbody > tr:hover td{background:none;}
.form-item{margin-bottom:15px;clear:both;border:1px solid #eee;}
.form-label{position:relative;float:left;display:block;padding:9px 15px;width:80px;font-weight:400;line-height:20px;text-align:right;background-color:#fafafa;}
.form-text .form-label{float: none;width: 100%;border-radius: 2px;box-sizing: border-box;text-align: left;}
.input-block{position:relative;margin-left:110px;min-height:36px;}
.form-text .input-block{margin: 0;left: 0;top: -1px;}
.form-input{display:block;padding-left:10px;width:50%;height:38px;line-height:1.3;line-height:38px\9;border:none;}
.form-text .form-textarea{position:relative;width: 90%;min-height: 100px;height:auto;line-height:20px;border-radius: 0 0 2px 2px;padding: 6px 10px;resize: vertical;border: none;}
.form-radio{margin:12px 0 0 12px;}
<?php echo $title;?>
<?php echo $content;?>