跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

网站在线文件管理

简单在线文件系统管理 文件的遍历,我还没写完找时间写 onlineEditor.php文件代码

//在线文件编辑器
/*-------------------------------------
   使用工厂设计模式,MVC实现
*/

class onlineEditor{

    //设置全局变量路径
    public $filePath = null;
    //设置过滤信息
    private $fileFilter = array(
        'onlineEditor.php',         
        'viewEditor.html',
        'index.php',
        '.',
        '..'
    );
    
    //构造函数必须是私有的在单例设计模式中
    function __construct($filePath){
        $this->filePath = $filePath;
    }

    //当本类销毁的时候进行的操作
    function __destruct(){
        // echo $this->filePath;
    }

    //获取文件的内容
    function getContent($filePath){
        if (!isset($filePath)) {
            
        } else{
            //获取文件内容
            $fileContent = file_get_contents($filePath);
            return $fileContent;
        }
    }

    //放入文件内容
    function putContent($filePath,$fileContent){
        file_put_contents($filePath, $fileContent);
    }

    //判断目录是否存在
    private function judgeExist(){
        //判断目录是否为空或者没有文件
        if(is_dir($this->filePath) && file_exists($this->filePath)){
            return true;
        } else{
            return false;
        }
    }

    //创建文件
    function createFile($filename){
        if(!file_exists($filename)){
            fopen($filename, "w+");
        }
            
        else{
            echo "点此返回";
             die("文件已经存在");
        }
            
    }
    //删除文件
    function delFile($filename){
        if(file_exists($filename)){
            unlink($filename);
        }
    }

    //主函数
    function main(){
        if($this->judgeExist()){
            //获取打开文件夹对象
            $fileOpen = opendir($this->filePath);
            $fileMes = array();
            $i = 0;
            //遍历文件夹
            while ($file = readdir($fileOpen)) {
                
                //过滤
                if(in_array($file, $this->fileFilter)){
                    continue;
                }
                
                $fileMesPush = array(
                    'fileCode'  => $i,
                    'fileName'  => $file,
                    'fileType'  => fileType($file),
                    'fileSize'  => fileSize($file),
                    'filemtime' => filemtime($file)
                );
                
                array_push($fileMes, $fileMesPush);
                $i++;
            }
            //关闭文件
           
            return $fileMes;
            fclose($fileOpen);
        } else{
            die("不存在此文件夹");
        }
    }

}

?>
index.php
    

    $dirPath = "./";  //设置操作目录 可改成自选操作目录
    $action = null;

    //引入文件
    require "./onlineEditor.php";

    //获得onlineEditor对象
    $onlineEditor = new onlineEditor($dirPath);
    $fileMes = $onlineEditor->main();

    //处理文件路径
    function subFilePath($dirPath,$filename){
        // echo $dirPath . $filename;
        return $dirPath . $filename;
    }

    //初始化
    if(array_key_exists('action', $_GET)){
        switch ($_GET['action']) {
            case 'updata':
                $action = 'updata';
                break;
            case 'del':
                $onlineEditor->delFile(subFilePath($dirPath,$_GET['filename']));
                $action = 'del';
                echo subFilePath($dirPath,$_GET['filename']);
                echo "";
                break;
        }
    } else{
        $action = null;
    }

    if(array_key_exists('action', $_POST)){
        switch ($_POST['action']) {
            case 'create':
                $onlineEditor->createFile(subFilePath($dirPath,$_POST['filename']));
                echo "";
                break;
        }
    }

    //获取文件内容
    if(array_key_exists('filename', $_GET) && $_GET['action'] == 'updata'){
        $root = subFilePath($dirPath,$_GET['filename']);
        $fileContent = $onlineEditor -> getContent($root);
    } else
        $fileContent = "坚持就是胜利";

    if (array_key_exists('filecontent', $_POST)) {
        // var_dump($_POST);
        $onlineEditor->putContent(subFilePath($dirPath,$_POST['filename']),$_POST['filecontent']);
        echo "";
    }    


    //引入界面
    require "./viewEditor.html";

    // print_r($fileMes);



?>
viewEditor.php


 
    在线文件编辑器
    
    




    

    


    

文件在线管理


    


    

    


         if($action == 'updata'){
    ?>
        

            

                
                " name="filename" />
                
                
                
            

        

        


         }
    ?>
    
    

        

            
            
            
        

    

    

        
            
                
            
                             foreach ($fileMes as $v){ 
            ?>
                
                    
                    
                    
                    
                    
                    
                    
                
                             }
            ?>
        
序号 文件名 文件类型 文件大小 创建日期 其他操作
 >修改  >删除

    

    



内容杂,详情请下载代码。 简单的文件在线管理.zip ( 4.36 KB 下载:144 次 ) AD:真正免费,域名+虚机+企业邮箱=0元

相关文章