FileContral.php
上传用户:gzlgcx
上传日期:2022-01-10
资源大小:3k
文件大小:8k
- <?php
- /*
- FileName : FileContral.php
- Desc : to dir all files on Server. can download files and delete files.
- author : Leslee
- email : leslee@ipn.cn
- */
- error_reporting(0);
- /* 上传文件 */
- function upfile($file_var,$tofile,$filepath){
- /* 参数说明:
-
- */
- if(!is_writable($filepath)){
- echo"$filepath 目录不存在或不可写";
- return false;
- exit;
- }
- //echo $_FILES["$file_var"]['name'];
- $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']." 上传失败.";
- return false;
- exit;
- }
- if (!move_uploaded_file($_FILES["$file_var"]['tmp_name'],$filepath.'/'.$uploadfile)){
- echo "上传失败。错误信息:n";
- print_r($_FILES);
- exit;
- }else{
- return $Array;
- }
- }else{
- return false;
- echo"无法上传";
- }
- }
- /* 获取文件大小 */
- 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 ($_GET['downfile']) {
- $downfile=$_GET['downfile'];
- if (!@is_file($downfile)) {
- echo "<script>alert("你要下的文件不存在")</script>";
- }
- $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("文件已不存在")</script>";
- }
- if(!file_exists($delfile)&&$exists!="1") {
- echo"<script>alert("删除成功")</script>";
- } else {
- echo"<script>alert("删除失败")</script>";
- }
- }
- /* 检测当前目录值 */
- $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("此目录名已经存在!")</script>";
- exit;
- }else {
- if(mkdir($newdir,0700))
- {
- echo"<script>alert("创建成功!")</script>";
- }else {
- echo "<script>alert("创建失败!")</script>";
- }
- }
- }
- /* 上传文件 */
- if($_POST['upload'])
- {
- if(!(upfile("upfiles",$_POST['fname'],$CurrentPath)))
- {
- echo"<script>alert("上传失败!")</script>";
- }else {
- echo "<script>alert("上传成功!")</script>";
- }
- }
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>FileContral v1.0 By Leslee</title>
- <style type="text/css">
- <!--
- body {
- font-family: "宋体";
- font-size: 12px;
- margin-left: 0px;
- margin-top: 0px;
- }
- table {
- font-family: "宋体";
- font-size: 12px;
- text-decoration: none;
- }
- .bold_blue {
- color: #003399;
- font-weight: bold;
- }
- input {
- border-right-width: 0.1mm;
- border-bottom-width: 0.1mm;
- border-top-style: none;
- border-right-style: solid;
- border-bottom-style: solid;
- border-left-style: none;
- border-right-color: #CCCCCC;
- border-bottom-color: #CCCCCC;
- }
- -->
- </style>
- </head>
- <body>
- <table width="770" border="0" align="center" cellpadding="5" cellspacing="0">
- <tr>
- <td align="right" bgcolor="#BCBCBC"><font color="White">PHP版本:</font><font color=red><?php echo PHP_VERSION;?></font> <font color="White"> 服务器:</font><font color=red><?php echo php_uname();?></font></td>
- </tr>
- <tr>
- <td bgcolor="#DDDDDD"><table width="100%" height="100%" border="0" cellpadding="5" cellspacing="2" bgcolor="#F5F5F5">
- <tr><form name="form1" method="post" action="">
- <td><span class="bold_blue"><strong>目录选择</strong>:</span> <input name="path" type="text" id="path">
- <input type="submit" name="Submit" value="跳 转"></td></form>
- </tr>
- <tr><form name="form2" method="post" action="">
- <td><span class="bold_blue"><strong>新建目录</strong>:</span> <input name="dirname" type="text" id="dirname">
- <input type="submit" name="Submit" value="建 立"></td></form>
- </tr><form name="form3" method="post" action="" enctype="multipart/form-data">
- <tr>
- <td><span class="bold_blue"><strong>上传文件</strong>:</span> <input name="upfiles" type="file" id="upfiles">
- </td>
- </tr>
- <tr>
- <td><span class="bold_blue"><strong> 新文件名</strong>:</span> <input name="fname" type="test" id="fname">
- <input type="submit" name="upload" value="上 传"></td>
- </tr></form>
- <tr>
- <td><span class="bold_blue">当前路径:</span><font color=red><?php echo $CurrentPath;?></font></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td bgcolor="#DDDDDD"><table width="100%" border="0" cellspacing="0" cellpadding="5">
- <tr>
- <td bgcolor="#BCBCBC"><strong>子目录</strong></td>
- </tr>
- <tr>
- <td>
- <table width="100%" border="0" cellpadding="0" cellspacing="5" bgcolor="#EFEFEF">
- <?php
- $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>【目录】 <a href="?path=".urlencode($CurrentPath)."/".urlencode($file)."">$file</a></td>n";
- echo "</tr>n";
- } else {
- if($file=="..")
- {
- echo "<tr bgcolor="#EFEFEF">n";
- echo "<td>【上级】 <a href="?path=".urlencode($CurrentPath)."/".urlencode($file)."">上级目录</a></td>";
- echo "</tr>n";
- }
- }
- }
- }
- @closedir($fso);
- ?>
- </table>
- </td>
- </tr>
- <tr>
- <td bgcolor="#BDBEBD"><strong>文件列表</strong></td>
- </tr>
- <tr>
- <td>
- <table width="100%" border="0" cellpadding="0" cellspacing="5" bgcolor="#EFEFEF">
- <tr >
- <td><b>文件名</b></td>
- <td><b>修改日期</b></td>
- <td><b>文件大小</b></td>
- <td><b>操作</b></td>
- </tr>
- <?php
- $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><a href="?downfile=".urlencode($CurrentPath)."/".urlencode($file)."">下载</a> | <a href="?path=".urlencode($CurrentPath)."&delfile=".urlencode($CurrentPath)."/".urlencode($file)."">删除</a></td>n";
- echo "</tr>n";
- }
- }
- @closedir($fso);
- ?></table>
- </td>
- </tr>
- </table></td>
- </tr>
- <tr>
- <td bgcolor="#DDDDDD">
- <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) 2005 <a href = mailto:leslee@ipn.cn><font color="red"><b>Leslee</b></font></a> All Rights Reserved . </td></tr></table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </body>
- </html>