首页 > 编程技术 > php

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

发布时间:2016-11-25 17:35

[原创]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

//

最后一个文件就是js.js文件了.

var xmlhttp=false;
 function aa(obj)
 {
  obj.className='aa';
  obj.onblur=function(){obj.className='bb';}
 }
 function resizepic(thispic) {
  //$('imgbox').style.width = $('divbox').clientWidth;
  if(thispic.height>55||thispic.width>55)thispic.style.zoom=56/(thispic.height>thispic.width?thispic.height:thispic.width);

 }

 function resizeimg(thispic){

  if(thispic.height>100||thispic.width>100)thispic.style.zoom=180/(thispic.height>thispic.width?thispic.height:thispic.width);
 }

上面这些是对图片进行缩放的.不过在fox也像有一点问题.

function Losefocus(obj,path){ //这里是创建文件时判断文件合法性,然后发带参数发送给rename.php文件,

 var ivalue=obj.value; 

 if( 'New folder' == ivalue || !ivalue.match(/^\w{1,255}$/i)){

  alert('输入合法文件夹名!');

  obj.select();

  return false;

 }else{  
  CreateAjax();
  var url="rename.php?path="+encodeURI(path.replace("/","\/"))+"&nname="+encodeURI(obj.value)+"&action=mkdir&rd="+Math.random();


  Senddata('GET',url,ReturnValue,'mkdir');


  document.getElementById('t1').innerHTML=ivalue;


  window.location.reload();


 }


}

下面还有今天就不写了,手都打痛了.明天接着来.

[原创]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//

上面我们讲到了,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传值判断,显示结果给用户看的.]

上一篇

标签:[!--infotagslink--]

您可能感兴趣的文章: