码迷,mamicode.com
首页 > Web开发 > 详细

php 文件删除

时间:2020-12-15 11:58:30      阅读:3      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!