⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileman.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?
/*
* File hander class
* @package YABInstaller
* @author stephen yabziz
*
*/
class FileMan {
    var $dirnums=0;
    var $filenums=0;
    var $totalsize=0;
    var $files=array();
    var $_error='';
    var $_all_error='';

	var $sDir='.';
    var $dDir='';
    var $action='';
    var $ext='all';
    var $permsValue='';
    
    var $ftpmode=FTP_ASCII;
    var $debug=false;

	function FileMan() {

	}
    function SetSourceDir($dir='.')
    {
        if($dir==null||!file_exists($dir))
        {
            $this->SetError("Source directory [$dir] can't be found!");
            return false;
        }
        $this->sDir=$dir;
        return true;
    }
    function SetDestDir($dir='.')
    {
        //if($dir==null||!file_exists($dir)) die("Dest directory [$dir] can't be found!");
        $this->dDir=$dir;
    }
    function Compare($sDir,$dDir,$cDir=flase)
    {
        $new_main = $new_comp = $unchanged_files = $changed_files = $new_files = array();

        if(!$this->SetSourceDir($sDir)) return false;;
        $main=$this->View();
        foreach($main as $sfile)
        {
            if($sfile[name]!=$this->sDir)
            $new_main[substr($sfile[name],strlen($this->sDir)+1)]=$sfile[folder];
        }

        if(!$this->SetSourceDir($dDir)) return false;;
        $comp=$this->View();
        foreach($comp as $sfile)
        {
            if($sfile[name]!=$this->sDir)
            $new_comp[substr($sfile[name],strlen($this->sDir)+1)]=$sfile[folder];
        }
        $new_files      = array_diff(array_keys($new_main),array_keys($new_comp));

        foreach($new_main as $file => $dir)
        {
            if(in_array($file,$new_files)) continue;

            if($dir) {/*@mkdir($cDir.'/'.$file); */ continue;}

            $ok=md5_file($sDir.'/'.$file) == md5_file($dDir.'/'.$file);
            if($ok)
            {
                $unchanged_files[]=$sDir.'/'.$file;
                $results .= "<font color=blue>".$file."</font> unchanged\n";//.md5_file('install-1.0/' .$file).':'. md5_file('install-1.1/'.$file)."\n";
            }
            else
            {
                if($cDir)
                {
                    $this->preparecopy($cDir.'/'.$file);
                    if(!is_dir($sDir.'/'.$file))copy($sDir.'/'.$file,$cDir.'/'.$file);
                }
                $changed_files[]=$sDir.'/'.$file;
                $results .= "<font color=red>".$file."</font> changed\n";//.md5_file('install-1.0/' .$file).':'. md5_file('install-1.1/'.$file)."\n";
            }
        }
        if($cDir)
        foreach($new_files as $file)
        {
            if(is_dir($sDir.'/'.$file)) continue;
            $this->preparecopy($cDir.'/'.$file);
            if(!is_dir($sDir.'/'.$file))copy($sDir.'/'.$file,$cDir.'/'.$file);
        }
        return array('new'=>$new_files,'changed'=>$changed_files,'unchanged'=>$unchanged_files);

    }
    function preparecopy($dfile)
    {
        $dirs=split('/',$dfile);
        array_pop($dirs);

        $basedir='';
        foreach($dirs as $dir)
        {
           if(!is_dir($basedir.$dir)){mkdir($basedir.'/'.$dir);}
           $basedir .= $dir.'/';
        }
    }
    function SetError($error)
    {
        $this->_all_error.=$this->_error="<font color=red>".$error."</font><br>";
    }
    function GetLastError()
    {
        return  $this->_error;
    }
    function GetError()
    {
        return  $this->_all_error;
    }
    function debug($msg)
    {
        if($this->debug)
        {
           flush();
           echo $msg."<br>";
        }
    }
    function FTPGet($lfile,$rfile)
    {
        if(@ftp_get($this->ftpconn,$lfile,$rfile,$this->ftpAsciiBinary($sfile)))
        {
           $this->debug("ftp get file:".$rfile." to ".$lfile);
           return true;
        }
        else
        {
           $this->SetError("ftp get file:".$rfile." to ".$lfile);
           return false;
        }
    }
    function FTPPut($rfile,$lfile)
    {
        if(@ftp_put($this->ftpconn,$rfile,$lfile,$this->ftpAsciiBinary($sfile)))
        {
           $this->debug("ftp put file:".$lfile." to ".$rfile);
           return true;
        }
        else
        {
           $this->SetError("ftp put file:".$lfile." to ".$rfile);
           return false;
        }
    }
    function FTPDelete($file)
    {
        if(@ftp_delete($this->ftpconn,$file))
        {
           $this->debug("ftp delete file:".$file);
           return true;
        }
        else
        {
           $this->SetError("ftp delete file:".$file);
           return false;
        }
    }
    function FTPSite($cmd)
    {
        if(@ftp_site($this->ftpconn,$cmd))
        {
           $this->debug("ftp site commond:".$cmd);
           return true;
        }
        else
        {
           $this->SetError("ftp site commond:".$cmd);
           return false;
        }
    }
    function FTPMkDir($newdir)
    {
        if(@ftp_mkdir($this->ftpconn,$newdir))
        {
            $this->debug("ftp get file:".$sfile." to ".$dfile);
            return true;
        }
        else
        {
            $this->SetError("ftp get file:".$sfile." to ".$dfile);
            return false;
        }
    }
    function GetContent($getUrl)
    {
        $fp=@fopen($getUrl,'r');
        while ($t=@fread($fp,1024) ) {
        $content.=$t;
        }
        return $content;
    }
    /**

    */
    function View()
    {
        $this->action='view';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        return $this->_LocalProcessor();
    }
    /**

    */
    function GetFiles()
    {
        $this->action='getfiles';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        return $this->_LocalProcessor();
    }
    /**
    
    */
    function Copy()
    {
        $this->action='copy';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_LocalProcessor();
    }
    /**

    */
    function Copy2FTP()
    {
        $this->action='remoteupload';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_LocalProcessor();
    }
    /**

    */
    function DelFiles()
    {
        $this->action='delfile';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_LocalProcessor();
    }
    /**

    */
    function Delete()
    {
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='delfile';
        $this->_LocalProcessor();
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='deldir';
        $this->_LocalProcessor();
    }
    /**

    */
    function Rename()
    {
        if(!$this->newext)
        {
           $this->debug("New extenstion is not defined!");
           return 0;
        }
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='rename';
        $this->_LocalProcessor();
    }
    /**

    */
    function ChmodDir()
    {
        if(!$this->permsValue)
        {
           $this->debug("Perms value is not defined!");
           return 0;
        }
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='chmoddir';
        $this->_LocalProcessor();
    }
    /**

    */
    function ChmodFiles()
    {
        if(!$this->permsValue)
        {
           $this->debug("Perms value is not defined!");
           return 0;
        }
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='chmodfiles';
        $this->_LocalProcessor();
    }
    /**

    */
    function Chmod()
    {
        $this->action='chmod';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_LocalProcessor();
    }
    /**

    */
    function FTPView()
    {
        $this->action='view';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPGetFiles()
    {
        $this->action='getfiles';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        return $this->_FTPProcessor();
    }
    /**

    */
    function FTPRename()
    {
        if(!$this->newext)
        {
           $this->debug("New extenstion is not defined!");
           return 0;
        }
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='rename';
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPDownload()
    {
        $this->action='download';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPCopy2FTP()
    {
        $this->action='remoteupload';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_LocalProcessor();
    }
    /**

    */
    function FTPDelFiles()
    {
        $this->action='delfile';
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPDeletes()
    {
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='delfile';
        $this->_FTPProcessor();
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='deldir';
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPChmodDir()
    {
        if(!$this->permsValue)
        {
           $this->debug("Perms value is not defined!");
           return 0;
        }
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='chmoddir';
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPChmodFiles()
    {
        if(!$this->permsValue)
        {
           $this->debug("Perms value is not defined!");
           return 0;
        }
        $this->dirnums=$this->filenums=$this->totalsize=0;
        $this->action='chmodfiles';
        $this->_FTPProcessor();
    }
    /**

    */
    function FTPChmod()
    {
        if(!$this->permsValue)
        {
           $this->debug("Perms value is not defined!");
           return 0;
        }
        $this->action='chmod';
        $this->_FTPProcessor();
    }
    function echoBar($size,$files,$dirs)
    {
    global $totalsizes,$totalfiles,$totaldirs;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -