FileContral.php
上传用户:gzlgcx
上传日期:2022-01-10
资源大小:3k
文件大小:8k
源码类别:

Ftp客户端

开发平台:

PHP

  1. <?php
  2. /*
  3. FileName : FileContral.php
  4. Desc : to dir all files on Server. can download files and delete files.
  5. author : Leslee
  6. email : leslee@ipn.cn
  7. */
  8. error_reporting(0);
  9. /* 上传文件 */
  10. function upfile($file_var,$tofile,$filepath){
  11. /* 参数说明:
  12. */
  13. if(!is_writable($filepath)){
  14. echo"$filepath 目录不存在或不可写";
  15. return false;
  16. exit;
  17. }
  18. //echo $_FILES["$file_var"]['name'];
  19. $Filetype=substr(strrchr($_FILES["$file_var"]['name'],"."),1); 
  20. ($tofile==='')?($uploadfile = $_FILES["$file_var"]['name']):($uploadfile = $tofile.".".$Filetype);//文件名
  21.      $Array[tofile] = $tofile.'.'.$Filetype;
  22.  $Array[oldfile]= $_FILES["$file_var"]['name'];
  23. if(!($uploadfile==='')){
  24. if (!is_uploaded_file($_FILES["$file_var"]['tmp_name'])){
  25.              echo $_FILES["$file_var"]['tmp_name']." 上传失败.";
  26.  return false;
  27.              exit;
  28. }
  29.     if (!move_uploaded_file($_FILES["$file_var"]['tmp_name'],$filepath.'/'.$uploadfile)){
  30.              echo "上传失败。错误信息:n";
  31.              print_r($_FILES);
  32.              exit;
  33.  }else{
  34.  return $Array;
  35.  }
  36. }else{
  37. return false;
  38. echo"无法上传";
  39. }
  40. }
  41. /* 获取文件大小 */
  42. function getSize(&$fs)
  43. {
  44. if($fs<1024)
  45. return $fs."Byte";
  46. elseif($fs>=1024&&$fs<1024*1024)
  47. return @number_format($fs/1024, 3)." KB";
  48. elseif($fs>=1024*1024 && $fs<1024*1024*1024)
  49. return @number_format($fs/1024*1024, 3)." M";
  50. elseif($fs>=1024*1024*1024)
  51. return @number_format($fs/1024*1024*1024, 3)." G";
  52. }
  53. // 下载文件
  54. if ($_GET['downfile']) {
  55. $downfile=$_GET['downfile'];
  56. if (!@is_file($downfile)) {
  57. echo "<script>alert("你要下的文件不存在")</script>";
  58. }
  59. $filename = basename($downfile);
  60. $filename_info = explode('.', $filename);
  61. $fileext = $filename_info[count($filename_info)-1];
  62. header('Content-type: application/x-'.$fileext);
  63. header('Content-Disposition: attachment; filename='.$filename);
  64. header('Content-Description: PHP3 Generated Data');
  65. readfile($downfile);
  66. exit;
  67. }
  68. // 删除文件
  69. if(@$_GET['delfile']!="") {
  70. $delfile=$_GET['delfile'];
  71. if(file_exists($delfile)) {
  72. @unlink($delfile);
  73. } else {
  74. $exists="1";
  75. echo "<script>alert("文件已不存在")</script>";
  76. }
  77. if(!file_exists($delfile)&&$exists!="1") {
  78. echo"<script>alert("删除成功")</script>";
  79. } else {
  80. echo"<script>alert("删除失败")</script>";
  81. }
  82. }
  83. /* 检测当前目录值 */
  84. $CurrentPath = $_POST['path']?$_POST['path']:($_GET['path']?$_GET['path']:false);
  85. if($CurrentPath===false)
  86. {
  87. $CurrentPath = dirname(__FILE__);
  88. }
  89. $CurrentPath = realpath(str_replace('\','/',$CurrentPath));
  90. /* 检查完毕 */
  91. /* 新建 目录 */
  92. if($_POST['dirname'])
  93. {
  94. $newdir = $CurrentPath."/".$_POST['dirname'];
  95. if(is_dir($newdir))
  96. {
  97. echo"<script>alert("此目录名已经存在!")</script>";
  98. exit;
  99. }else {
  100. if(mkdir($newdir,0700))
  101. {
  102. echo"<script>alert("创建成功!")</script>";
  103. }else {
  104. echo "<script>alert("创建失败!")</script>";
  105. }
  106. }
  107. }
  108. /* 上传文件 */
  109. if($_POST['upload'])
  110. {
  111. if(!(upfile("upfiles",$_POST['fname'],$CurrentPath)))
  112. {
  113. echo"<script>alert("上传失败!")</script>";
  114. }else {
  115. echo "<script>alert("上传成功!")</script>";
  116. }
  117. }
  118. ?>
  119. <html>
  120. <head>
  121. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  122. <title>FileContral v1.0 By Leslee</title>
  123. <style type="text/css">
  124. <!--
  125. body {
  126. font-family: "宋体";
  127. font-size: 12px;
  128. margin-left: 0px;
  129. margin-top: 0px;
  130. }
  131. table {
  132. font-family: "宋体";
  133. font-size: 12px;
  134. text-decoration: none;
  135. }
  136. .bold_blue {
  137. color: #003399;
  138. font-weight: bold;
  139. }
  140. input {
  141. border-right-width: 0.1mm;
  142. border-bottom-width: 0.1mm;
  143. border-top-style: none;
  144. border-right-style: solid;
  145. border-bottom-style: solid;
  146. border-left-style: none;
  147. border-right-color: #CCCCCC;
  148. border-bottom-color: #CCCCCC;
  149. }
  150. -->
  151. </style>
  152. </head>
  153. <body>
  154. <table width="770" border="0" align="center" cellpadding="5" cellspacing="0">
  155.   <tr>
  156.     <td align="right" bgcolor="#BCBCBC"><font color="White">PHP版本:</font><font color=red><?php echo PHP_VERSION;?></font> &nbsp;&nbsp;&nbsp;<font color="White"> 服务器:</font><font color=red><?php echo php_uname();?></font></td>
  157.   </tr>
  158.   <tr>
  159.     <td bgcolor="#DDDDDD"><table width="100%" height="100%" border="0" cellpadding="5" cellspacing="2" bgcolor="#F5F5F5">
  160.       <tr><form name="form1" method="post" action="">
  161.         <td><span class="bold_blue"><strong>目录选择</strong>:</span>          <input name="path" type="text" id="path">
  162.           <input type="submit" name="Submit" value="跳 转"></td></form>
  163.       </tr>
  164.       <tr><form name="form2" method="post" action="">
  165.         <td><span class="bold_blue"><strong>新建目录</strong>:</span>          <input name="dirname" type="text" id="dirname">
  166.           <input type="submit" name="Submit" value="建 立"></td></form>
  167.       </tr><form name="form3" method="post" action="" enctype="multipart/form-data">
  168.       <tr>
  169.         <td><span class="bold_blue"><strong>上传文件</strong>:</span>          <input name="upfiles" type="file" id="upfiles">
  170.           </td>
  171.       </tr>
  172.       <tr>
  173.         <td><span class="bold_blue"><strong> 新文件名</strong>:</span>          <input name="fname" type="test" id="fname">
  174.           <input type="submit" name="upload" value="上 传"></td>
  175.       </tr></form>
  176.       <tr>
  177.         <td><span class="bold_blue">当前路径:</span><font color=red><?php echo $CurrentPath;?></font></td>
  178.       </tr>
  179.     </table>
  180.     </td>
  181.   </tr>
  182.   <tr>
  183.     <td bgcolor="#DDDDDD"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
  184.       <tr>
  185.         <td bgcolor="#BCBCBC"><strong>子目录</strong></td>
  186.       </tr>
  187.       <tr>
  188.       <td>
  189.       <table width="100%" border="0" cellpadding="0" cellspacing="5" bgcolor="#EFEFEF">
  190.       <?php
  191. $fso=@opendir($CurrentPath);
  192. while ($file=@readdir($fso)) {
  193. $fullpath = "$CurrentPath/$file";
  194. $is_dir = @is_dir($fullpath);
  195. if($is_dir=="1"){
  196. if($file!=".."&&$file!=".") {
  197. echo "<tr bgcolor="#EFEFEF">n";
  198. echo "  <td>【目录】 <a href="?path=".urlencode($CurrentPath)."/".urlencode($file)."">$file</a></td>n";
  199. echo "</tr>n";
  200. } else {
  201. if($file=="..")
  202. {
  203. echo "<tr bgcolor="#EFEFEF">n";
  204. echo "<td>【上级】 <a href="?path=".urlencode($CurrentPath)."/".urlencode($file)."">上级目录</a></td>";
  205. echo "</tr>n";
  206. }
  207. }
  208. }
  209. }
  210. @closedir($fso); 
  211. ?>
  212. </table>
  213. </td>
  214. </tr>
  215.       <tr>
  216.         <td bgcolor="#BDBEBD"><strong>文件列表</strong></td>
  217.       </tr>
  218.       <tr>
  219.        <td>
  220.        <table width="100%" border="0" cellpadding="0" cellspacing="5" bgcolor="#EFEFEF">
  221.           <tr > 
  222.             <td><b>文件名</b></td>
  223.             <td><b>修改日期</b></td>
  224.             <td><b>文件大小</b></td>
  225.             <td><b>操作</b></td>
  226.           </tr>
  227.       <?php
  228. $fso=@opendir($CurrentPath);
  229. while ($file=@readdir($fso)) {
  230. $fullpath = "$CurrentPath/$file";
  231. $is_dir = @is_dir($fullpath);
  232. if($is_dir=="0"){
  233. $size=@filesize("$CurrentPath/$file");
  234. $size=@getSize($size);
  235. $lastsave=@date("Y-n-d H:i:s",filemtime("$CurrentPath/$file"));
  236.     echo "<tr bgcolor="#EFEFEF">n";
  237.     echo "<td>◇ $file</td>n";
  238. echo "  <td>$lastsave</td>n";
  239.     echo "  <td>$size</td>n";
  240. echo "  <td><a href="?downfile=".urlencode($CurrentPath)."/".urlencode($file)."">下载</a> | <a href="?path=".urlencode($CurrentPath)."&delfile=".urlencode($CurrentPath)."/".urlencode($file)."">删除</a></td>n";
  241. echo "</tr>n";
  242. }
  243. }
  244. @closedir($fso); 
  245. ?></table>
  246. </td>
  247. </tr>
  248.     </table></td>
  249.   </tr>
  250.   <tr>
  251.   <td bgcolor="#DDDDDD">
  252.   <table width="100%"  border="0" cellspacing="0" cellpadding="5">
  253.       <tr>
  254.         <td bgcolor="#BCBCBC"><strong>CopyRight</strong></td>
  255.       </tr>
  256.       <tr>
  257.       <td>
  258.       <table width="100%" border="0" cellpadding="0" cellspacing="5" bgcolor="#EFEFEF">
  259.       <tr>
  260.       <td>Copyright (C) 2005 <a href = mailto:leslee@ipn.cn><font color="red"><b>Leslee</b></font></a> All Rights Reserved . </td></tr></table>
  261.       </td>
  262.       </tr>
  263.       </table>      
  264.   </td>
  265.   </tr>
  266. </table>
  267. </body>
  268. </html>