我的func单文件管理器(PHP)

发布时间:2008年03月06日      浏览次数:2354 次
<?php
error_reporting(0);
if (isset($_GET['ok']) && $_GET['ok']==="参数,自已设定")
{
      $_COOKIE['admin']="yes";
      $cx="ok=".$_GET['ok'];
}
if (isset($_COOKIE['admin']) && $_COOKIE['admin']==="yes")
{
      function upfile($file_var,$tofile,$filepath)
      {
            if(!is_writable($filepath)){
                  echo"$filepath folder not exist";
                  return false;
                  exit;
            }
            $Filetype=substr(strrchr($_FILES["$file_var"]['name'],"."),1);
            ($tofile==='')?($uploadfile = $_FILES["$file_var"]['name']):($uploadfile = $tofile.".".$Filetype);
             $Array[tofile] = $tofile.'.'.$Filetype;
             $Array[oldfile]= $_FILES["$file_var"]['name'];
            if(!($uploadfile==='')){
                  if (!is_uploaded_file($_FILES["$file_var"]['tmp_name'])){
                         echo $_FILES["$file_var"]['tmp_name']." upload error.";
                         return false;
                         exit;
                  }
                  if (!move_uploaded_file($_FILES["$file_var"]['tmp_name'],$filepath.'/'.$uploadfile)){
                         echo "upload error。info:\n";
                         print_r($_FILES);
                         exit;
                         }else{
                         return $Array;
                         }
            }else{
                  return false;
            echo"cannot upload";
            }
      }
      function getSize(&$fs)
      {
            if($fs<1024)
                  return $fs."Byte";
            elseif($fs>=1024&&$fs<1024*1024)
                  return @number_format($fs/1024, 3)." KB";
            elseif($fs>=1024*1024 && $fs<1024*1024*1024)
                  return @number_format($fs/1024*1024, 3)." M";
            elseif($fs>=1024*1024*1024)
                  return @number_format($fs/1024*1024*1024, 3)." G";
      }
      if (isset($_GET['downfile']) && $_GET['downfile']) {
            $downfile=$_GET['downfile'];
            if (!@is_file($downfile)) {
                  echo "<script>alert(\"file not exist\");history.go(-1);</script>";
                  exit;
            }
            $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;
      }
      if(@$_GET['delfile']!="") {
            $delfile=$_GET['delfile'];
            if(file_exists($delfile)) {
                  @unlink($delfile);
            } else {
                  $exists="1";
                  echo "<script>alert(\"file not exist\");history.go(-1);</script>";
                  exit;
            }
            if(!file_exists($delfile)&&$exists!="1") {
                  echo"<script>location.href='?".$cx."&path=".$_GET['path']."';</script>";
                  exit;
            } else {
                  echo"<script>alert(\"delete error\");history.go(-1);</script>";
                  exit;
            }
      }
      $CurrentPath      = $_POST['path']?$_POST['path']:($_GET['path']?$_GET['path']:false);
      if($CurrentPath===false)
      {
            $CurrentPath      = dirname(__FILE__);
      }
      $CurrentPath      = realpath(str_replace('\\','/',$CurrentPath));
      if($_POST['dirname'])
      {
            $newdir      = $CurrentPath."/".$_POST['dirname'];
            if(is_dir($newdir))
            {
                  echo"<script>alert(\"folder already exist!\");history.go(-1);</script>";
                  exit;
            }else {
                  if(mkdir($newdir,0700))
                  {
                        echo"<script>location.href='?".$cx."&path=".$_GET['path']."';</script>";
                        exit;
                  }else {
                        echo "<script>alert(\"create error!\");history.go(-1);</script>";
                        exit;
                  }
            }
      }
      if($_GET['deldirname'])
      {
            $deldir      = $_GET['deldirname'];
            if(is_dir($deldir))
            {
                  if (@rmdir($deldir))
                  {
                        echo"<script>location.href='?".$cx."&path=".$_GET['path']."';</script>";
                        exit;
                  }
                  else
                  {
                        echo "<script>alert(\"folder delete error!\");history.go(-1);</script>";
                        exit;
                  }
            }else {
                  echo "<script>alert(\"folder not exist!\");history.go(-1);</script>";
                  exit;
            }
      }
      if($_POST['upload'])
      {
            if(!(upfile("upfiles",$_POST['fname'],$CurrentPath)))
            {
                  echo"<script>alert(\"upload error!\");history.go(-1);</script>";
                  exit;
            }else {
            }
      }
      echo"
      <meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
      <style type='text/css'>body,table {font-size: 12px;margin-left: 0px;margin-top: 0px;}</style>
      <table width='770' border='0' align='center' cellpadding='5' cellspacing='0'>
            <tr>
                  <td align='right' bgcolor='#BCBCBC' colspan=2>
                        <font color='White'>PHP Edition:</font><font color=red>".PHP_VERSION."</font>    
                        <font color='White'> Server:</font><font color=red>". php_uname()."</font>    
                  </td>
            </tr>
            <tr>
                  <td bgcolor='#DDDDDD' colspan=2>
                        <table width='100%' height='100%' border='0' cellpadding='5' cellspacing='2' bgcolor='#F5F5F5'>
                              <tr>
                                    <form name='form1' method='post' action=''>
                                          <td width='40%' nowrap>
                                                <span class='bold_blue'><strong>Folder</strong>:</span>
                                                <input name='path' type='text' id='path'>
                                                <input type='submit' name='Submit' value='Goto'>
                                          </td>
                                    </form>
                                    <form name='form2' method='post' action=''>
                                          <td width='60%' nowrap> <span class='bold_blue'><strong>New Folder</strong>:</span>
                                                <input name='dirname' type='text' id='dirname'>
                                                <input type='submit' name='Submit' value='Create'>
                                          </td>
                                    </form>
                              </tr>
                              <tr>
                                    <form name='form3' method='post' action='' enctype='multipart/form-data'>
                                          <td colspan='2' nowrap>
                                                <span class='bold_blue'><strong>Upload File</strong>:</span>
                                                <input name='upfiles' type='file' id='upfiles'>  
                                                <span class='bold_blue'><strong> New File Name</strong>:</span>
                                                <input name='fname' type='test' id='fname'>
                                                <input type='submit' name='upload' value='Upload'>
                                          </td>
                                    </form>
                              </tr>
                              <tr>
                                    <td colspan='2'>
                                          <span class='bold_blue'>This URL:</span>
                                          <font color=red>".$CurrentPath."</font>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
            <tr>
                  <td bgcolor='#DDDDDD' width='30%' valign='top'>
                        <table width='100%' border='0' cellspacing='0' cellpadding='5'>
                              <tr>
                                    <td bgcolor='#BCBCBC'><strong>Children Folder</strong></td>
                              </tr>
                              <tr>
                                    <td>
                                          <table width='100%' border='0' cellpadding='0' cellspacing='5' bgcolor='#EFEFEF'>
      ";
                                          $fso=@opendir($CurrentPath);
                                          while ($file=@readdir($fso)) {
                                                $fullpath      = "$CurrentPath/$file";
                                                $is_dir            = @is_dir($fullpath);
                                                if($is_dir=="1"){
                                                if($file!=".."&&$file!=".")      {
                                                      echo "<tr bgcolor=\"#EFEFEF\">\n";
                                                      echo " <td>【Folder】 <a href=\"?".$cx."&path=".urlencode($CurrentPath)."/".urlencode($file)."\">$file</a>    <a href=\"?".$cx."&path=".urlencode($CurrentPath)."&deldirname=".urlencode($CurrentPath)."/".urlencode($file)."\" onclick=\"if (window.confirm('Do you real delete this a folder?')){return true;}else{return false;}\"><font color=#999999>Del</font></a></td>\n";
                                                      echo "</tr>\n";
                                                } else {
                                                      if($file=="..")
                                                      {
                                                            echo "<tr bgcolor=\"#EFEFEF\">\n";
                                                            echo "<td colspan='2'><font color=green>【UP】</font> <a href=\"?".$cx."&path=".urlencode($CurrentPath)."/".urlencode($file)."\"><font color=green>UP Folder</font></a></td>";
                                                            echo "</tr>\n";
                                                      }
                                                }
                                                }
                                          }
                                          @closedir($fso);
      echo"
                                          </table>
                                    </td>
                              </tr>
                        </table>
                  </td>
                  <td bgcolor='#DDDDDD' valign='top'>
                  <table width='100%' border='0' cellspacing='0' cellpadding='5'>
                        <tr>
                              <td bgcolor='#BDBEBD'><strong>Listed Files</strong></td>
                        </tr>
                        <tr>
                              <td>
                                    <table width='100%' border='0' cellpadding='0' cellspacing='5' bgcolor='#EFEFEF'>
                                          <tr >
                                                <td><b>File Name</b></td>
                                                <td><b>Edit Date</b></td>
                                                <td><b>File size</b></td>
                                                <td><b>Operate</b></td>
                                          </tr>
      ";
                                    $fso=@opendir($CurrentPath);
                                    while ($file=@readdir($fso)) {
                                          $fullpath      = "$CurrentPath/$file";
                                          $is_dir            = @is_dir($fullpath);
                                          if($is_dir=="0"){
                                          $size=@filesize("$CurrentPath/$file");
                                          $size=@getSize($size);
                                          $lastsave=@date("Y-n-d H:i:s",filemtime("$CurrentPath/$file"));
                                          echo "<tr bgcolor=\"#EFEFEF\">\n";
                                          echo "<td>◇ $file</td>\n";
                                          echo " <td>$lastsave</td>\n";
                                          echo " <td>$size</td>\n";
                                          echo " <td nowrap><a href=\"?".$cx."&downfile=".urlencode($CurrentPath)."/".urlencode($file)."\">Download</a> | <a href=\"?".$cx."&path=".urlencode($CurrentPath)."&delfile=".urlencode($CurrentPath)."/".urlencode($file)."\" onclick=\"if (window.confirm('Do you real delete this a file?')){return true;}else{return false;}\">Del</a></td>\n";
                                          echo "</tr>\n";
                                          }
                                    }
                                    @closedir($fso);
      echo "
                                    </table>
                              </td>
                        </tr>
                  </table>
                  </td>
            </tr>
            <tr>
                  <td bgcolor='#DDDDDD' colspan=2>
                        <table width='100%' border='0' cellspacing='0' cellpadding='5'>
                              <tr>
                                    <td bgcolor='#BCBCBC'><strong>CopyRight</strong></td>
                              </tr>
                              <tr>
                                    <td>
                                          <table width='100%' border='0' cellpadding='0' cellspacing='5' bgcolor='#EFEFEF'>
                                                <tr>
                                                      <td>Copyright (C) 2008 All Rights Reserved . </td>
                                                </tr>
                                          </table>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
      </table>
      ";
}
?>
文章来源:桂林唯创网络
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!