www.gusucode.com > mcms手机网站系统 v3.1源码程序 > mcms_v3.1.0/upload/app/admin/file.php

    <?php
/*
 * MCMS Copyright (c) 2012-2013 ZhangYiYeTai Inc.
 *
 *  http://www.mcms.cc
 *
 * The program developed by loyjers core architecture, individual all rights reserved,
 * if you have any questions please contact loyjers@126.com
 */

require_once(dirname(__FILE__) . "/../../init.php"); //公用引导启动文件
check_login();
check_level('C11',AJAX);
$time_start = H :: getmicrotime(); //开始时间

// 动作处理
call_mfunc();

// 模板处理
require_once(assign_tpl(basename(__FILE__), 'admin'));

// ******************************************************* 函数方法 *******************************************************
function m__list(){
    global $dbm,$result,$p;
    $file_url = isset($_GET['file_url'])?trim($_GET['file_url']):'';
    $start_time = isset($_GET['start_time'])?trim($_GET['start_time']):'';
    $end_time = isset($_GET['end_time'])?trim($_GET['end_time']):'';
    $params['where'] = " 1=1";

    if($file_url!='') $params['where'].=" and file_url like '%{$file_url}%'";
    if($start_time!='' && $end_time=='') $params['where'].=" and create_time>=".strtotime($start_time);
    if($start_time=='' && $end_time!='')  $params['where'].=" and create_time<=".strtotime($end_time);
    if($start_time!='' && $end_time!='') {
        $params['where'].=" and create_time>=".strtotime($start_time)." and create_time<=".strtotime($end_time);
    }
    $params['table_name'] = TB_PRE . "file";
    $params['count'] = 1 ;
    $params['suffix'] = " order by create_time desc ";
    $params['pagesize'] = get_pagesize(PAGESIZE_ADMIN);
    $params['suffix'] .= $dbm -> get_limit_sql($params['pagesize'], $p);
    $result = $dbm -> single_query($params);
}

//批量删除
function m__del(){
    global $dbm,$C;
    $_POST=H::sqlxss($_POST);
    $_POST['params']=isset($_POST['params'])?trim($_POST['params']):'';
    $_POST['params']=explode(',',$_POST['params']);
    //print_r($_POST['params']);die();
    foreach($_POST['params'] as $v){
        $sql="select file_url from ".TB_PRE."file where file_md5='$v' limit 1";
        $rs=$dbm->query($sql);
        if(count($rs['list'])==1) {
            $file=$rs['list'][0]['file_url'];
            //删除文件
            @unlink(ROOT_PATH.$file);
            //循环删除空目录
            del_upload_dir($file);

            //删除缩略图
            $preview_url = H::preview_url($file);
            unlink(ROOT_PATH.$preview_url);
            del_upload_dir($preview_url);

            //die();
            //删除数据
            $sql = "delete from " . TB_PRE . "file where file_md5='$v'";
            $rs = $dbm->query_update($sql);

        }
    }
    die('{"code":"0","msg":"操作成功"}');
}

//循环删除空目录
function del_upload_dir($file){
    $dirs=explode('/',$file);
    $dir_new='';
    $dir_arr=array();
    foreach($dirs as $d){
        $dir_new.=$d.'/';
        array_push($dir_arr,$dir_new);
    }
    unset($dir_arr[count($dir_arr)-1]);
    foreach(array_reverse($dir_arr) as $d){
        $tfiles=H::get_files(ROOT_PATH.$d);//print_r($tfiles);
        $tdirs=H::get_dirs(ROOT_PATH.$d);//print_r($tdirs);
        if(count($tfiles==0) && count($tdirs)==0){
            @rmdir(ROOT_PATH.$d);
        }
    }
}
function check_used($file_md5,$file_url){
    global $dbm,$C;
    $ret=array();

    //判断配置文件是否引用
    $con=file_get_contents(ROOT_PATH.'/config/cache/global.php');
    if(strstr($con,$file_url)) array_push($ret,'配置文件 /config/cache/global.php');

    //判断是否被文档表引用
    $sql="select count(*) as t from ".TB_PRE."info_list where info_img='$file_url' or info_body like '%$file_url%'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'文档 '.$rs['t'] .' 次');

    //判断是否被文档附件表引用
    $sql="select count(*) as t from ".TB_PRE."attach where file_md5='$file_md5'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'文档附件 '.$rs['t'] .' 次');

    //判断是否被分类表引用
    $sql="select count(*) as t from ".TB_PRE."category where clogo='$file_url' or clogo_hover='$file_url' or cintro like '%$file_url%'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'分类 '.$rs['t'] .' 次');

    //判断是否被广告表引用
    $sql="select count(*) as t from ".TB_PRE."adv where  area_html like '%$file_url%'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'代码广告 '.$rs['t'] .' 次');
    $sql="select count(*) as t from ".TB_PRE."adv_img where img_url='$file_url'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'轮播广告 '.$rs['t'] .' 次');

    //判断是否被友链表引用
    $sql="select count(*) as t from ".TB_PRE."flink where fimg='$file_url'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'友情链接 '.$rs['t'] .' 次');

    //判断是否被微信自动回复引用
    $sql="select count(*) as t from ".TB_PRE."weixin_auto_msg where msg_pic='$file_url'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'微信自动回复 '.$rs['t'] .' 次');

    //判断是否被微信自动回复引用
    $sql="select count(*) as t from ".TB_PRE."user where avatar='$file_url'";
    $rs=$dbm->scalar($sql);//print_r($rs);
    if($rs['t']>0) array_push($ret,'用户头像 '.$rs['t'] .' 次');

    //遍历模型
    foreach($C->model as $k=>$v){
        $warr=array();//print_r($v);die();
        foreach($v['fields'] as $k1=>$v1){
            if($v1['form_type']=='image') array_push($warr,$k1."='$file_url'");
            if($v1['form_type']=='editor') array_push($warr,$k1." like '%$file_url%'");
        }
        if(count($warr)>0) {
            $sql = "select count(*) as t from " . TB_PRE . $k . " where ".implode(" or ",$warr);
            $rs=$dbm->scalar($sql);//print_r($rs);
            if($rs['t']>0) array_push($ret,'模型 '.$k.' '.$rs['t'] .' 次');
        }
    }

    return implode('<br>',$ret);
}
?>