<html>
<head>
<title>文件管理</title>
<meta charset=
'utf-8'
/>
</head>
<body>
<?php
$dir
=dirname(
__FILE__
);
if
(isset(
$_GET
[
'a'
])){
switch
(
$_GET
[
'a'
]){
case
'creat'
:
$filename
=
$_POST
[
"filename"
];
$filename
=rtrim(
$dir
,
"/"
).
"/"
.
$filename
;
file_put_contents
(
$filename
,
""
);
break
;
case
'del'
:
unlink(
$_GET
[
'filename'
]);
break
;
case
'ch'
:
chmod
(
$_GET
[
'filename'
],0777);
break
;
case
'update'
:
file_put_contents
(
$_POST
[
'filename'
],
$_POST
[
'content'
]);
echo
"修改成功"
;
header(
"refresh:1;url=index.php"
);
break
;
}
}
?>
<center>
<h1>文件管理</h1>
<form action=
'index.php?a=creat'
method=
'post'
>
文件:<input type=
'text'
name=
'filename'
/>
<input type=
'submit'
value=
'新建'
/>
</form>
<table border=
'1'
width=
'900'
cellpadding=
'5'
cellspacing=
'0'
>
<tr>
<th>文件名</th>
<th>类型</th>
<th>大小</th>
<th>创建时间</th>
<th>所有者</th>
<th>权限</th>
<th>操作</th>
</tr>
<?php
$dd
=opendir(
$dir
);
while
(false !== (
$f
=readdir(
$dd
))){
if
(
$f
==
"."
||
$f
==
".."
){
continue
;
}
$file
=rtrim(
$dir
,
"/"
).
"/"
.
$f
;
$f2
=iconv(
"gb2312"
,
"utf-8"
,
$f
);
echo
"<tr>"
;
echo
"<td>{$f2}</td>"
;
echo
"<td>"
.
filetype
(
$file
).
"</td>"
;
echo
"<td>"
.
filesize
(
$file
).
"</td>"
;
echo
"<td>"
.
date
(
"Y-m-d H:i:s"
,
filectime
(
$file
)).
"</td>"
;
echo
"<td>"
.
fileowner
(
$file
).
"</td>"
;
echo
"<td>"
.
substr
(sprintf(
"%o"
,
fileperms
(
$file
)),-4).
"</td>"
;
echo
"<td align=
'center'
>
<a href=
'index.php?a=edit&filename={$file}'
>修改</a>|
<a href=
'index.php?a=del&filename={$file}'
>删除</a>|
<a href=
'index.php?a=ch&filename={$file}'
>
chmod
</a>
</td>";
echo
"</tr>"
;
}
?>
</table>
<?php
if
(isset(
$_GET
[
'a'
]) &&
$_GET
[
'a'
]==
'edit'
){
echo
"<hr/>"
;
echo
"<form action='index.php?a=update' method='post'>"
;
echo
"文件名:<input type='text' name='filename' readonly value='{$_GET['filename']}' />"
;
echo
"<br/><br/>"
;
echo
"<textarea name='content' rows='5' cols='30'>"
.
file_get_contents
(
$_GET
[
'filename'
]).
"</textarea>"
;
echo
"<br/><br/>"
;
echo
"<input type='submit' value='保存修改' />"
;
echo
"</form>"
;
}
?>
</center>
</body>
</html>