[原创]php+ajax实现模拟Win文件管理系统五

 更新时间:2016年11月25日 17:35  点击:2334

[原创]php+ajax实现模拟Win文件管理系统

//

本教程由本站原创,转载请注明来处

作者:www.111cn.net

邮箱:drise@163.com

QQ:271728967

//

就是deldir()函数了这个函数的功能是删除文件

function deldir($dir){


    if(is_dir($dir)){


        $rdir = $dir;


        if($dirlist = scandir($rdir)){ //进行扫描目录
              array_shift($dirlist);去除".."
              array_shift($dirlist);去除"."
        foreach($dirlist as $d){ 


         $rd = $rdir.'/'.$d;


         if(isset($d) && is_file($rd)){ 


          unlink($rd);//删除文件


         }else{


          deldir($rd);//递归


         }


        }  


            rmdir($rdir);//删除空目录


        }else{


            return false;


        }


    }


    return true;


}

 

这个函数也用了递归算法,进行目录与文件的删除,

下面就是filename()函数了,这个函数的功能是对文件进行重命名

function Filename($path,$nname){

  // 取得旧文件名

 if($path == "" || substr($path,-1) =="/" || strlen($path)>255){

  exit('非法操作!');

 }else{
  $oname = substr($path,strrpos($path,"/")+1);
  $opath = substr($path,0,strlen($path) - strlen(substr($path,strrpos($path,"/")+1)));//获取文件的当前路径  

 }
  //重命名

 if(preg_match("/^\w{1,255}\.\w{1,8}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}\.\w{1,8}$/i",$oname,$otemp_name)){ //匹配文件名

  Rename_file_folder($path,$opath,$nname);//些函数下面讲到

 }else if( preg_match("/^\w{1,255}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}$/i",$oname,$otemp_name)){ //匹配文件夹名
  Rename_file_folder($path,$opath,$nname);
 }else{
  echo("File info Error");

 }}

function Rename_file_folder($path,$opath,$newname){
 if(is_dir($path)){
  if(is_writable($path)){

   if(is_dir($opath.$newname)){ exit("Sorry Dir is exists");}
   echo rename($path,$opath.$newname)?'Rename Success':'Rename Fail Error';
  }else{
   echo('Can\'t Rename dir not is_writable');

  }
 }else{
  if(file_exists($path) && is_writable($path)){
   if(file_exists($opath.$newname)){ exit("file exists"); }
   echo rename($path,$opath.$newname)?'Rename success ':'Rename fail';
  }else{
   echo "file can't is_writable";
  }
 }

}

上一篇

[原创]php+ajax实现模拟Win文件管理系统

//本教程由本站原创,转载请注明来处

作者:www.111cn.net

邮箱:drise@163.com

QQ:271728967

//

上面php文件讲完了,下面来讲一下,document.js文件.些文件来自互联网.

var subMenuSrcObj=null;
function ShowMenu(obj,x,y){


 try{

  subMenuSrcObj=obj;


  document.getElementById("subMenu").style.top=(ie_y(obj)+obj.offsetHeight+y)+"px";


  document.getElementById("subMenu").style.left=(ie_x(obj)+x)+"px";


 }catch(e)
 {  ;
 }


}


function loadsubMenu()


{


 document.body.insertAdjacentHTML("afterBegin","<div id=\"subMenu\" style=\"filter:progid:DXImageTransform.Microsoft.DropShadow(color=#333333,offX=1,offY=1,positives=true);position:absolute; left:-10025px; top:47px; width:100px; height:1px;background-color: #D4D0C8;z-index:99999\">s</div>");


}


function hiddenSubMenu1()


{


 document.getElementById("subMenu").style.left="-9000px";


}


function hiddenSubMenu()


{


 try


 {


 


 


 obj=document.getElementById("subMenu");


 temp=false;


 e=event.srcElement;


 if(e==obj)


 {


  temp=false;


 }else


 {


  temp=true;


  while(e=e.offsetParent)


  {


   if(e==obj||e==subMenuSrcObj)


   {


    temp=false;


   }


  }


 }


 if(event.srcElement==subMenuSrcObj)


 {


  temp=false;


 }


 if(temp&&parseInt(obj.style.left)>0)


 {


  hiddenSubMenu1();


 }


 }


 catch (e)


 {


 }


}


function ie_y(e){ 


 var t=e.offsetTop; 


 while(e=e.offsetParent){ 


  t+=e.offsetTop; 


 } 


 return t; 



function ie_x(e){ 


 var l=e.offsetLeft; 


 while(e=e.offsetParent){ 


  l+=e.offsetLeft; 


 } 


 return l; 


}


function del(){


  


  


}

 

 

    function myMenuShow(obj,btn)


    {


                document.getElementById("subMenu").innerHTML="<li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" onclick=\"alert('"+btn+"');\" >剪  切</li> <li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\">复  制</li><li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" >粘  贴</li> <hr><li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" onclick=\"del("+btn+");\">删 除</li> <hr><li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" onclick=\"alert('你单击文件名就可重命名!');\" >重命名</li><br/>";


                ShowMenu(obj,0,0);


                return false;


    }


document.onmousemove=hiddenSubMenu;


attachEvent('onload', loadsubMenu);// JavaScript Document//等一下只要这样调用就行了.

上一篇

 

[原创]php+ajax实现模拟Win文件管理系统

//本教程由本站原创,转载请注明来处

作者:www.111cn.net

邮箱:drise@163.com

QQ:271728967//

上面我们讲到了,Deletefile()函数,下面我们接着讲Createfolder()函数

function Createfolder($path,$nname){
 if(is_dir($path) && is_writable($path)){//是否为目录且可写
  if(preg_match("/^\w{1,255}$/i",$nname)){//判断文件的合法性
   echo mkdir($path."/".$nname,0777)?'Create Folder success':'Create Folder Fail';//0777是设置文件可读写
  }else{
   echo "Folder Error";
  }
 }else{
  echo "Can't Create Error file not is_writable or not dir";
 }}

这个函数的功能是实现文件夹的建,

Past($path,$nname,$cpath)函数

function Past($currentpath,$currentfilename,$filepote){ //1:文件要被粘贴到的位置2:当前文件{夹}名3:文件{夹}所在的物理地址  
  $str = substr($currentfilename,-1,1);
  if(substr($currentfilename,-1,1)=="|"){
   $currentfilename = str_replace("|","",$currentfilename);
   $filepote   = str_replace("|","",$filepote);
  }
  if(is_dir($currentpath) && is_writable($currentpath) && is_dir($filepote) && is_writable($filepote)){
   //@mkdir($currentpath."/".$currentfilename);
   $t=full_copy($filepote,$currentpath."/".$currentfilename)?'t':'f';//full_copy函数下面接,是进行递归读取文件夹
  }else if(is_file($filepote) && file_exists($filepote)){
   if(file_exists($currentpath.$currentfilename)){ echo ('file exists! plase rename it!');exit;}
    echo copy($filepote,$currentpath.$currentfilename)?'success':'errror';  
}  if( $str =="|" && $t='t' ){ 
   deldir($filepote);
  }
}

function full_copy( $source, $target )//这个函数来自php官方站,功能是进行文件夹递归拷贝文件
    {

        if ( is_dir( $source ) )
        {
            @mkdir( $target ); 
            $d = dir( $source );
            while ( FALSE !== ( $entry = $d->read() ) )
            {
            if ( $entry == '.' || $entry == '..' )
                {
                        continue;
                }
                $Entry = $source . '/' . $entry;
                if ( is_dir( $Entry ) )
                {
                   full_copy( $Entry, $target . '/' . $entry );
                    continue;
                }
                copy( $Entry, $target . '/' . $entry );
            }
            $d->close();
        }else {
            copy( $source, $target );
        }
    }

上一篇

[原创]php+ajax实现模拟Win文件管理系统

//本教程由本站原创,转载请注明来处

作者:www.111cn.net

邮箱:drise@163.com

QQ:271728967//

上一篇我们己讲了dir.php文件的作用了,下面我就讲rename.php文件每一个函数的功能.

 Refere();
 header("Content-type:text/html;charset=utf-8");//设置文档编码
 $path = isset($_GET['path'])?$_GET['path']:'';
 $nname = isset($_GET['nname'])?$_GET['nname']:'';
 $cpath = isset($_GET['copypath'])?$_GET['copypath']:'';
 $action = isset($_GET['action'])?$_GET['action']:'';
 switch($action){ 
  case 'del':  
   Deletefile($path); 
  break;
  case 'mkdir':
   Createfolder($path,$nname);
   break;
  case 'past':
   Past($path,$nname,$cpath);
   break;
  default: 
   Filename($path,$nname);
 } 
这里就是rename.php文件所有函数,下面我们来进行分析.

 Refere()函数

多人看到名称大概就知道什么用意了.下面看它的代码.

function Refere(){
 $referer=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'';
 if($referer =='' || is_null($referer) || empty($referer)){
  exit("Error Server Http 500");
 }

就这一小段,这里是为了,防止用户直接输入rename.php文件所做的最基本的安全保护方法,函数的就不说了.

 Deletefile()函数

function Deletefile($path){
 if(is_dir($path) && is_writable($path)){
  echo @rmdir($path)?'t':'fo';
 }else if(file_exists($path) && is_writable($path)){
  echo unlink($path)?'t':'ff';
 }else{
  exit("没有权限,Error http 404 ");
 }
}[上面输出的t,ff这是为后面返回是用ajax传值判断,显示结果给用户看的.]

上一篇

[原创]php+ajax实现模拟Win文件管理系统

//本教程由本站原创,转载请注明来处

作者:www.111cn.net

邮箱:drise@163.com

QQ:271728967//

接上面我们来看dir.php文件代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>


<head>


<meta http-equiv="Content-Type" content="text/html; charset=gb2312">


<title>无标题文档</title>


<script language="javascript" src="js/js.js"></script>


<style type="text/css">


<!--


.folder{


height:97px;


width:99px;


border:1px solid #e4e4e4;


text-align:center;


float:left;


margin:20px;


padding-top:15px;


color:#E4E4E4


}


#t{


height:97px;


width:99px;


border:1px solid #e4e4e4;


text-align:center;


float:left;


margin:20px;


padding-top:15px;


color:#E4E4E4;


display:none;


}


p{


text-align:center;


color:#000000;


font-size:12px;


width:90px;


white-space:nowrap;


text-overflow:ellipsis;


-o-text-overflow:ellipsis;


overflow: hidden;


margin-top:15px;


}


input{


width:80px;


border:1px solid #000;


height:18px;


}


#info{


border:1px solid #FF9933;


background-color:#FFFFE1;


display:none;


font-size:12px;


padding-top:7px;


text-align:left;


padding-left:10px;


width:300px;


}


li{


list-style-type:none;


list-style:none;


padding-left:0px;


font-size:12px;


cursor:default;


padding-top:2px;


}


#Layer1{


border:1px solid #28B9FF;


background-color:#ECF9FF;


padding:10px;


padding-top:20px;


line-height:30px;


height:20px;


display:none;


}


.up{width:300px; height:24px;border:1px;}


.bt{width:70px; height:24px;}


#tool{ height:47px; width:98%; margin:0px auto; background-image:url(image/tool_bg.jpg); margin-top:0px;padding-top:0px;padding-left:10px;}


.ta{display:inline-block;width:72px;height:30px; line-height:30px; text-align:center;margin-top:2px; color:#4D4D4D; text-decoration:none}


a.ta:hover{background:url("image/tool_if.gif") no-repeat ; height:30px;}


.aa{ background:url("image/tool_if.gif") no-repeat ; height:40px;}


.bb{ background:#fff;}


body {


 margin-left: 0px;


 margin-top: 10px;


 margin-right: 0px;


 margin-bottom: 0px;


}


-->


</style>


</head>


<body >

 

 

<?php

 $dir_path=isset($_GET['url'])?$_GET['url']:'..'; 

 //$totallen = strlen($dir_path);


 //$sublen  = strlen(substr($dir_path,strrpos($dir_path,"/")));


 $lastdir = substr($dir_path,0,strlen($dir_path)-strlen(substr($dir_path,strrpos($dir_path,"/"))));


 Tool($dir_path,$lastdir);  


 CheckDir($dir_path); 


 //echo "<br>";


 


 //echo substr($dir_path,0,(strlen($dir_path)-strrpos($dir_path,"/")+1));


 


function CheckDir($dir_path){// 这个函数是检查并显示当前目录下的文件及文件


  if(is_dir($dir_path)){  


   if($dir_file=opendir($dir_path)){


    while(($dir_list=readdir($dir_file))!==false)


     {


      if($dir_list!="." && $dir_list!=".."){//如果加这里判断等一在显示文件列表时.. .这样.


       echo("<div class='folder' oncontextmenu=\"return myMenuShow(this,'".$dir_path."/".$dir_list."','".$dir_path."/"."')\" id='".$dir_path."/".$dir_list."' ><a href='?url=".$dir_path."/".$dir_list."'><img src='".Getfiletype($dir_list)."' border=0 onload=\"resizepic(this);\"  /></a><p id='".$dir_list."' onClick=\"edit(this,'".$dir_path."/".$dir_list."');\" >".$dir_list."</p></div>\n");


      }


     }


   }else{


    echo($dir_path."<br/>");


   }


  }else{


   echo($dir_path."<br/>");


  }


  Folderexp($dir_path);


}


function Getfiletype($dir){//根据扩展名显示相应的图片


 global $_GET;


 if(@$_GET['url'] !='' and is_dir(@$_GET['url'])){


  $dir = $_GET['url'].'\\'.$dir;


 }


 //print_r( $dir);


 if($dir == '' || is_null($dir) || empty($dir)){return false;}


  if(is_dir($dir)){


   return 'fold.jpg';


  }else{


   return (Getextends($dir));


  }


}

 

 

function Getextends($dir){


 if($dir =="" || is_null($dir)){return "unkown.jpg";}


  $Extends_name = substr($dir,strrpos($dir,".")+1); 


  $Extends_img = array('jpg','jpeg','gif','png','bmp','psd'); 


 if(in_array($Extends_name,$Extends_img)){return $dir;}


   switch($Extends_name){


    case "php":


     return 'image/asp_php_jsp.jpg';


     break;


    case "asp":


     return 'image/asp_php_jsp.jpg';


     break;


    case "jsp":


     return 'image/asp_php_jsp.jpg';


     break;


    case "aspx":


     return 'image/asp_php_jsp.jpg';


     break;


    case "xml":


     return 'image/asp_php_jsp.jpg';


     break;


    case "htm":


     return 'image/html_js.jpg';


     break;


    case "html":


     return 'image/html_js.jpg';


     break;


    case "shtml":


     return 'image/html_js.jpg';


     break;


    case "js":


     return 'image/html_js.jpg';


     break; 


    case "txt":


     return 'image/txt.jpg';


     break;


    case "doc":


     return 'image/word.jpg';


     break;


    default:


     return 'image/fold.jpg';


     


   }


}


function Folderexp($dir_path){//新建文件夹


  echo("<div id='t0'></div>");


  echo("<div id=\"t\">");


  echo("<img src=\"image/fold.jpg\" width=\"52\" height=\"50\">");


  echo("<p id='t1'>");


  echo("<input  type=\"text\" value=\"New folder\"  onblur=\"Losefocus(this,'".$dir_path."');\"; >");


  echo("</p>");


  echo("</div>");


}


function Tool($dir_path,$lastdir){//这里显示菜单条


  echo("<div id=\"tool\">");


  echo("<a href=\"dir.php\" class=\"ta\"><img src=\"image/tool_root.gif\" border=\"0\"></a>");


  echo("<a href=\"#\" class=\"ta\" onclick=\"history.go(-1);\" ><img src=\"image/tool_back.gif\" border=\"0\"></a>");


  echo("<a href=\"#\" class=\"ta\" onclick=\"history.go(1);\" ><img src=\"image/tool_go.gif\" border=\"0\"></a>");


  echo("<a href=\"?url=$lastdir\" class=\"ta\"  title='返回上级目录'><img src=\"image/tool_s.gif\" border=\"0\"></a>");


  echo("<a href=\"#\" class=\"ta\" onclick=\"CreateText();\" title=\"新建文本文件\"><img src=\"image/tool_txt.gif\" border=\"0\"></a>");


  echo("<a href=\"#\" class=\"ta\" onClick=\"Createfolder();\" title=\"新建文件夹\" ><img src=\"image/tool_newfolder.gif\" border=\"0\"></a>");


  echo("<a href=\"#\" class=\"ta\" onclick=\"return Past('filepath','".$dir_path."')\" ><img src=\"image/tool_past.gif\" border=\"0\"></a>");


  echo("<a href=\"#\" class=\"ta\" onClick=\"Upload('".$dir_path."');\" title=\"文件上传\" ><img src=\"image/tool_upload.gif\" border=\"0\"></a>");


  echo("</div>");


}


?>


<div id="Layer1" style="position:absolute; width:480px; height:20px; z-index:1; left: 293px; top: 143px;">
</div>

</body>


</html>

 上一篇

 

[!--infotagslink--]

相关文章

  • python实现学生通讯录管理系统

    这篇文章主要为大家详细介绍了python实现学生通讯录管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-25
  • 护卫神 主机管理系统使用说明(MSSQL管理)

    护卫神·主机管理系统该版本支持在Windows Server 200320082012,含32位和64位,直接开设配置WEB站、FTP站,以及SQL Server和MySQL,是您开设和管理虚拟主机的绝好帮手。但是对于新用户可能在使用上有一些困难,因此请仔细阅读如下说明文档...2016-01-27
  • 深入C# 内存管理以及优化的方法详解

    本篇文章是对C#中内存管理以及优化的方法进行了详细的分析介绍,需要的朋友参考下...2020-06-25
  • 详解swift中xcworkspace多项目管理

    给大家详细讲解了IOS开发中swift语言xcworkspace多项目管理的方法和介绍,一起参考一下。...2020-06-30
  • js实现车辆管理系统

    这篇文章主要为大家详细介绍了js实现车辆管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-08-26
  • php需登录的文件上传管理系统

    本文给大家介绍一个不错的需要登录的php 文件上传管理系统,功能简单有需要了解的同学可参考。 代码如下<&#63;php$admin_pw="admin";//管理密码$uploaddir="upload";//上传目录session_start();if($_GET['action']=="g...2015-10-30
  • thinkphp自定义权限管理之名称判断方法

    下面小编就为大家带来一篇thinkphp自定义权限管理之名称判断方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2017-04-03
  • C++学生信息管理系统

    这篇文章主要为大家想详细介绍了C++学生信息管理系统的实现代码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
  • C语言学生成绩管理系统小设计

    这篇文章主要为大家详细介绍了C语言学生成绩管理系统小设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
  • C#毕业设计之Winform零压健身房管理系统

    本文介绍了个人的《零压健身房管理系统(扁平化)》的基本流程和功能点的介绍,虚心接受各位的意见,欢迎在提出宝贵的意见,大家一起探讨学习...2021-09-26
  • 如何管理Vue中的缓存页面

    这篇文章主要介绍了如何管理Vue中的缓存页面,帮助大家更好的理解和学习使用vue框架,感兴趣的朋友可以了解下...2021-02-06
  • jQuery技巧之让任何组件都支持类似DOM的事件管理

    这篇文章主要介绍了jQuery技巧之让任何组件都支持类似DOM的事件管理 的相关资料,需要的朋友可以参考下...2016-04-06
  • C#实现微信公众号会员卡管理的示例代码

    这篇文章主要介绍了C#实现微信公众号会员卡管理的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-25
  • vue前端开发辅助函数状态管理详解示例

    vue的应用状态管理提供了mapState、mapGetters、mapMutations、mapActions四个辅助函数,所谓的辅助函数分别对State、Getters、Mutations、Actions在完成状态的使用进行简化...2021-10-10
  • C++顺序表实现图书管理系统

    这篇文章主要为大家详细介绍了C++顺序表实现图书管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-10-13
  • 基于python实现银行管理系统

    这篇文章主要介绍了基于python实现银行管理系统,文中有非常详细的代码示例,对正在学习python项目制作的小伙伴们有很好的帮助,需要的朋友可以参考下...2021-04-19
  • 40行代码把Vue3的响应式集成进React做状态管理

    这篇文章主要介绍了40行代码把Vue3的响应式集成进React做状态管理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-05-20
  • 详解Java如何使用集合来实现一个客户信息管理系统

    读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用Java 集合实现一个客户信息管理系统,大家可以在过程中查缺补漏,提升水平...2021-11-11
  • [原创]php+ajax实现模拟Win文件管理系统五

    [原创]php+ajax实现模拟Win文件管理系统 // 本教程由本站原创,转载请注明来处 作者:www.111cn.net 邮箱:drise@163.com QQ:271728967 // 就是deldir()函数了这个函数的...2016-11-25
  • NPOINT免费虚拟主机管理系统windows2003的安装方法【图文】第1/2页

    这是一款免费的虚拟主机管理系统,无限制,并可以二次开发...2016-01-27