这是最早用PHP写过的一个文件管理系统,管理的是Web服务器端的文件
功能主要有
- 创建文件
- 删除文件
- 编辑文件
- 地址栏
- 文件列表
- 文件夹进入
- 文件夹创建
- 文件夹删除
- 图片显示
此系统仅运行在WIN平台上
PHP code
<?php
define("BANQUAN","__ V2.3 | MSN:mail@lizhong.me | Power by qttc.net");
if(!(isset($tijiao)) && !(isset($dirr))){
$dirr="d:/";
}
if($tijiao){
if($_GET["add"]=="Please improt filename"){
$error="Warning:Please in the improt right's filename";
$dirr=str_replace("\\","/",$_GET["url"]);
}elseif($_GET["add"]){
$error=action($subb);
$dirr=str_replace("\\","/",$_GET["url"]);
}elseif($_GET["del"]){
$yest=action($subb);
$dirr=$_GET["url"];
}elseif($_GET["adddir"]){
$dirr=$_GET["url"];
if($_GET["adddir"]=="Please improt directroyname"){
$error="Warning: Please in the improt right's Directroyname";
$dirr=str_replace("\\","/",$_GET["url"]);
}else{
$error=action($subb);
}
}elseif($_GET["info"]){
$dirr=str_replace("//","/",$_GET["info"]);
}elseif($_GET["dirr"]){
if(file_exists($_GET["dirr"]) && is_dir($_GET["dirr"])){
$dirr=str_replace("\\","",$_GET["dirr"]);
}else{
$dirr=str_replace("\\","",$_GET["dirr"]);
$adderres="Sorry: No find the directroy of \"".$_GET["dirr"]."\"";
}
}elseif($_GET["edit"]){
$dirr=str_replace("\\","/",dirname($_GET["url"]));
$edit=$_GET["edit"];
$urllee=$_GET["url"];
$editfile=$urllee."/".$edit;
}elseif($_POST["editsave"]){
$dirr=str_replace("\\","/",dirname($_POST["editsave"]));
$newconten=$_POST["newconten"];
$wenjianmingming=basename($_POST["editsave"]);
$xierulala=fopen($_POST["editsave"],"r+");
fwrite($xierulala,$newconten);
fclose($xierulala);
$yest="\"$wenjianmingming is saved!";
}elseif($_GET["viw"]){
$dirr=str_replace("\\","/",$_GET["url"]);
$viw=$_GET["viw"];
$chatoububu=dirname($dirr);
$phototo=$chatoububu."/".$viw;
}elseif($_GET["tijiao"]=="photo"){
$dirr=str_replace("\\","/",$_GET["url"]);
}
}
function deldir($deldir){
$dell=opendir($deldir);
while($fdell=readdir($dell)){
if($fdell!="." && $fdell!=".."){
$deldirr=$deldir."/".$fdell;
if(is_dir($deldirr)){
deldir($deldirr);
}elseif(is_file($deldirr)){
unlink($deldirr);
}
}
}
closedir($dell);
rmdir($deldir);
}
function dirsize($muludir){
$b=opendir($muludir);
while($a=readdir($b)){
if($a!="." && $a!=".."){
$aa=$muludir."/".$a;
if(is_dir($aa)){
$sum+=dirsize($aa);
}elseif(is_file($aa)){
$sum+=filesize($aa);
}
}
}
closedir($b);
return $sum;
}
function action($sub){
$url=$_get["url"];
switch($sub){
case 1:
$add=$_GET["add"];
$dirr=$_GET["url"];
$newfile=$dirr."/".$add;
if(!file_exists($newfile)){
fopen("$newfile","w");
$dirr=dirname($newfile);
$error="\"".$add."\" file set up already";
return $error;
break;
}else{
$error="Sorry : The \"$add\" is existed!";
return $error;
break;
}
case 2:
$url=$_GET["url"];
$del=$_GET["del"];
$delfile=$url."/".$del;
if(file_exists($delfile)){
unlink($delfile);
$yest="The \"$del\" File deleted";
return $yest;
break;
}else{
$yest="Sorry : The File \"$del\" no exist!";
return $yest;
break;
}
case 3:
$dirr=$_GET["url"];
$adddir=$_GET["adddir"];
$adddor=$dirr."/".$adddir;
if(!file_exists($adddor)){
mkdir($adddor);
$dirr=dirname($adddor);
$error="\"".$adddir."\" Directroy set up already";
return $error;
break;
}else{
$error="Sorry : The directroy \"".$adddir."\" is existed!";
return $error;
break;
}
case 4:
$url=$_GET["url"];
$del=$_GET["del"];
$delfile=$url."/".$del;
if(file_exists($delfile)){
deldir($delfile);
$yest="\"".$del."\" Directory deleted";
return $yest;
break;
}else{
$yest=" Sorry: The directro \"y$del\" is no exist! ";
return $yest;
break;
}
}
}
?>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++网页 区+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++页头 区+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Briefness manage file system <?php echo BANQUAN; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
body {
background:
}
a {
text-decoration:none;
color:red;
}
.jiacu {
font-weight:bold;
font-size:13px;
color:
}
</style>
</head>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++页头区 END+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++内容 区+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<body>
<!-- ++++++++++++++++++++++++文件列表表格++++++++++++++++++++++++++ -->
<center><h2>Briefness manage file system</h2></center>
<hr width="60%">
<!-- ++++++++++++++++++++++++显示当前操作目录++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++导航栏++++++++++++++++++++++++++ -->
<div style="width:798px; height:30px; margin:20px auto 0px; border:1px solid #4c89ca;">
<div style="width:650px; float:left; margin-left:20px; font-size:15px; font-weight:bold; line-height:30px; color:#fff;">
<!-- ++++++++++++++++++++++++GOTO表单++++++++++++++++++++++++++ -->
<form action="a.php" method="get">
Operate Current Directroy :
<input type="text" name="dirr" size="60" value="<?php echo $dirr; ?>" />
<input type="submit" name="tijiao" value="goto" />
</form>
<!-- ++++++++++++++++++++++++GOTO表单END++++++++++++++++++++++++++ -->
</div>
<div style="float:right;
line-height:22px;
margin:5px 10px auto auto;
text-align:center;
width:70px; height:20px;
font-weight:bold;
background:#0f0;
color:#fff;
border-bottom:1px solid #666;
border-right:1px solid #666;">
<a style="color:#4a4c4a;" href="a.php?tijiao=ok&dirr=<?php echo dirname($dirr); ?>"><<Back</a>
</div>
<div style="clear:blod;"></div>
</div>
<!-- ++++++++++++++++++++++++GOTO错误提示++++++++++++++++++++++++++ -->
<?php
if($adderres){
echo "<div style=\"width:798px; height:25px; border:1px solid #9d94ca; margin:0px auto; line-height:0px; text-align:center;\">
<p style=\"line-height:0px; color:#760E18; font-size:13px; font-weight:bold;\">$adderres</p>
</div>";
}
?>
<!-- ++++++++++++++++++++++++GOTO错误提示END++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++导航栏END++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++显示当前操作目录END++++++++++++++++++++++++++ -->
<table align="center" width="800" border="1">
<tr>
<th width="300">File & Directroy Name</th>
<th>Type</th>
<th>Size</th>
<th>Mod-time</th>
<th>Option</th>
</tr>
<?php
$summm=0;
$dirmmm=0;
$filemmm=0;
$zongsize=0;
if(file_exists($dirr) && is_dir($dirr)){
if($bb=opendir($dirr)){
while($hh=readdir($bb)){
if($hh!="." && $hh!=".."){
$filehaha=$dirr."/".$hh;
$summm++;
if(is_dir($filehaha)){
echo "<tr><td style=\"font-weight:bold;\">$hh</td>";
$dirmmm++;
}elseif(is_file($filehaha)){
echo "<tr><td>$hh</td>";
$filemmm++;
}
echo "<td>".ucfirst(filetype($filehaha))."</td>";
if(is_dir($filehaha)){
$dani=dirsize($filehaha);
if($dani==""){
echo "<td>0 bytes</td>";
}else{
if($dani<1024)
echo "<td>$dani Bytes</td>";
elseif($dani<1024*1024)
echo "<td>".sprintf("%0.2f",$dani/1024)." KB</td>";
elseif($dani<1024*1024*1024)
echo "<td>".sprintf("%0.2f",$dani/1024/1024)." MB</td>";
else
echo "<td>".sprintf("%0.2f",$dani/1024/1024/1024)." GB</td>";
$zongsize+=$dani;
}
}elseif(is_file($filehaha)){
$danini=filesize($filehaha);
if($danini<1024)
echo "<td>$danini Bytes</td>";
elseif($danini<1024*1024)
echo "<td>".sprintf("%0.2f",$danini/1024)." KB</td>";
elseif($danini<1024*1024*1024)
echo "<td>".sprintf("%0.2f",$danini/1024/1024)." MB</td>";
else
echo "<td>".sprintf("%0.2f",$danini/1024/1024/1024)." GB</td>";
$zongsize+=$danini;
}
echo "<td>".date("Y-m-d H:i",filemtime($filehaha))."</td>";
if(is_dir($filehaha)){
echo "<td><a href='a.php?tijiao=ok&subb=4&del={$hh}&url={$dirr}'> DEL</a>";
echo "<a href='a.php?tijiao=ok&info={$filehaha}'> <font color='#00FFFF'>INTO</font></a></td></tr>";
}elseif(is_file($filehaha)){
echo "<td><a href='a.php?tijiao=ok&subb=2&del={$hh}&url={$dirr}'> DEL</a>";
if(preg_match("/\.(txt|php|asp|log|ini|css|js|htm|html)$/i",$filehaha)){
echo "<a href='a.php?tijiao=ok&edit={$hh}&url={$dirr}'> <font color='#0000FF'>EDIT</font></a></td></tr>";
}elseif(preg_match("/\.(jpeg|gif|ico|png|jpg|bmp)$/i",$filehaha)){
echo "<a href='a.php?tijiao=ok&viw={$hh}&url={$dirr}'> <font color='#FFFF00'>LOOK</font></a></td></tr>";
}else{
echo " <font color='#cccccc'>UNOP</font></td></tr>";
}
}
}
}
}
}
?>
</table>
<!-- +++++++++++++++++++++++++++++++++++文件列表表格END++++++++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++++++++++++状态栏++++++++++++++++++++++++++++++ -->
<div style="width:798px; margin:20px auto 20px; height:40px; border:1px dashed #00f; line-height:50px;">
<span style="
position:relative;
display:block;
color:#fff;
font-size:13px;
text-align:center;
line-height:25px;
font-weight:bold;
width:250px;
height:20px;
background:#9d94ca;
top:-15px; left:20px;">State and File-Directroy Tole sum:</span>
<div style="
position:relative;
top:-40px;
width:790px;
text-align:left;
margin:20px auto 0px;
height:40px;
font-weight:bold;
font-size:13px;
color:#0f0;">
<?php
if($summm==0){
echo " The directroy is empty! ";
}else{
echo " Object $summm <font color='white'> | </font> ";
if($dirmmm==0)
echo " Dir No <font color='white'> | </font>";
else
echo " Dir $dirmmm <font color='white'> | </font>";
if($filemmm==0)
echo " Dir No <font color='white'> | </font> ";
else
echo " File $filemmm <font color='white'> | </font> ";
if($zongsize<1024){
echo " Allsize $zongsize bytes";
}elseif($zongsize<1024*1024){
echo " Allsize ".sprintf("%0.2f",$zongsize/1024)." KB";
}elseif($zongsize<1024*1024*1024){
echo " Allsize ".sprintf("%0.2f",$zongsize/1024/1024)." MB";
}else{
echo " Allsize ".sprintf("%0.2f",$zongsize/1024/1024/1024)." GB";
}
echo "<div style=\"float:right; width:280px; height:40px;\">";
echo " Diskfree ".sprintf("%0.2f",disk_free_space($dirr)/1024/1024/1024)." G <font color='white'> | </font>";
echo " Diskspace ".sprintf("%0.2f",disk_total_space($dirr)/1024/1024/1024)." G";
echo "</div>";
}
?>
</div>
<div style="clear:both;"></div>
<!-- +++++++++++++++++++++++++++++++++++状态栏END++++++++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++消息提示++++++++++++++++++++++++++ -->
<center><font color="blue"><?php echo $yest; ?></font></center>
<!-- ++++++++++++++++++++消息提示END++++++++++++++++++++++ -->
<br />
<!-- +++++++++++++++++++++++++++++++++++添加文件或文件夹表格+++++++++++++++++++++++++ -->
<table align="center" border="0" width="500">
<!-- +++++++++++++++添加文件表单域+++++++++++++ -->
<form action="a.php" method="get">
<input type="hidden" name="subb" value="1" />
<input type="hidden" name="url" value="<?php echo $dirr; ?>" />
<tr>
<td width="450" align="right">AddFile: <input type="text" name="add" size="50" value="Please improt filename" /></td>
<td><input type="submit" name="tijiao" value="OK" /></td>
</tr>
</form>
<!-- ++++++++++++++++添加文件表单域END++++++++++++++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++添加文件夹表单域++++++++++++++++++++++++++++++ -->
<form action="a.php" method="get">
<input type="hidden" name="subb" value="3" />
<input type="hidden" name="url" value="<?php echo $dirr; ?>" />
<tr>
<td width="450" align="right">AddDirectory:
<input type="text" name="adddir" size="50" value="Please improt directroyname" /></td>
<td><input type="submit" name="tijiao" value="OK" /></td>
</tr>
</form>
<!-- ++++++++++++++++++++++添加文件夹表单域END+++++++++++++++++++++ -->
</table>
<!-- +++++++++++++++++++++++++++++++++++添加文件或文件夹表格END++++++++++++++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++消息提示++++++++++++++++++++++++++ -->
<center><font color="red"><?php echo $error; ?></font></center>
<br />
<!-- ++++++++++++++++++++消息提示END++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++编辑页面区+++++++++++++++++++++++++++++++++++++ -->
<?php
if($editfile){
$duquwenben=file_get_contents($editfile);
echo "<table width=500 align=center border=1><form action=a.php method=post>";
echo "<tr><td>Editing: $edit </td></tr>";
echo "<tr><td height=300><textarea name=newconten rows=20 cols=100>".htmlspecialchars($duquwenben)."</textarea></td></tr>";
echo "<input type=hidden name=editsave value=$editfile />";
echo "<tr><td align=center><input type=submit name=tijiao value=Save /><input type=reset value=reset /></td></tr>";
echo "</form></table>";
}
if($phototo){
echo "<div style=\"weight:798px; min-height:200px; border:1px solid #ccc; text-align:center;\">";
echo "<a style='margin:auto;' href='a.php?tijiao=photo&url=$dirr' title='Click Off'><img src=\"file:///{$phototo}\" /></a>";
echo "<div style=\"weight:798px; min-height:20px; text-align:center; vertical-align:middle;\">$viw</div>";
}
?>
<!-- ++++++++++++++++++++++++++++++++编辑页面区END+++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++页脚区++++++++++++++++++++++++++++++++++-->
<div style="width:900px;
margin:60px auto;
text-align:center;
line-height:40px;
color:#666;
border-top:2px solid #666;
font-size:15px;
height:40px;
font-weight:bold;">
Power by qttc.net © 2011
</div>
</body>
</html>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++内容 区+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
...