php 文件删除

2020-12-16 23:03

阅读:461

标签:tab   public   sse   load   pat   write   cti   ima   rpc   

    /** @JsonRpcMethod- delFile*/
    public function delFile($data){
        if(empty($data->filename)){
            throw new Exception(‘参数错误‘,3104); 
        }else{
            $filename = $data->filename;
        }
        
        if(isset($data->filedata) && isset($data->id)){
            if(empty($data->filedata) || $data->filedata == "" || $data->filedata ==null){
                $filedata = [];
            }else{
                $filedata = $data->filedata;
            }
            $row = $this->db->update(
                self::$table, [
                    "upload_image"    =>json_encode($filedata),
                    "update_time"    =>date("Y-m-d H:i:s",time())
                ],["id[=]"=>$data->id]
            );
            
            
        }
        
        $path = str_replace( ‘\\‘, ‘/‘ , realpath(dirname(__FILE__).‘/../../‘)).‘/upload_pl/‘.$filename;
        //var_dump($path);exit;
        $url=iconv(‘utf-8‘,‘gbk‘,$path);
        if(PATH_SEPARATOR == ‘:‘){ //linux
            if(file_exists($path)){
                $del = unlink($path);
            }else{
                throw new Exception(‘文件不存在‘,3104);
            }
            
        }else{  //Windows
            $url = str_replace( ‘/‘ , ‘\\‘ , $url);
            //var_dump($url);exit;
            if(file_exists($url)){
                $del = unlink($url);
            }else{
                throw new Exception(‘文件不存在‘,3104);
            }
        }
        if (!$del){
            throw new Exception(‘删除失败‘,3104);
        }else{
            //$this->write_log(["删除","知识库,附件名称".$filename,"ItKnowledge"]);
            return ‘success‘;
        }    
                        
    }

 

php 文件删除

标签:tab   public   sse   load   pat   write   cti   ima   rpc   

原文地址:https://www.cnblogs.com/gaogaoxingxing/p/14107593.html


评论


亲,登录后才可以留言!