Ejemplo n.º 1
0
function m__save()
{
    global $dbm, $page, $dbkdir;
    check_level("E0901");
    $page['list'] = get_tables_name();
    $table = @trim($_GET['table']);
    if (!isset($table) && empty($table)) {
        die('{"code":"100","msg":"请选择要备份数据表"}');
    }
    if (isset($_GET['first']) && intval($_GET['first']) == 1) {
        $config = $_SERVER['DOCUMENT_ROOT'] . SITE_PATH . '/core/config.php';
        $cf = @file_get_contents($config);
        if (!$cf) {
            die('{"code":"1","msg":"配置读取失败"}');
        }
        $v = uniqid();
        set_config('RAND_BAK', $v, $cf);
        $cf = @file_put_contents($config, $cf);
        if (!$cf) {
            die('{"code":"1","msg":"写入配置失败,可能 core/config.php 文件没有写权限"}');
        }
        $dbkdir = '../backup_' . $v . '/';
        if (!is_dir($dbkdir)) {
            helper::mkdirs($dbkdir);
        }
    }
    //判断备份目录是否有可写的权限
    if (is_dir($dbkdir)) {
        $iswrite = @fopen($dbkdir . 'dd.txt', 'w');
        if ($iswrite) {
            $is_write = 1;
            fclose($iswrite);
            unlink($dbkdir . 'dd.txt');
        } else {
            $is_write = 0;
        }
        if (!$is_write) {
            die('{"code":"200","msg":"目录没有写的权限"}');
        }
    }
    $tables = strpos($table, ',') !== false ? explode(',', $table) : array($table);
    if (isset($_GET['first']) && $_GET['first'] == 1) {
        foreach (glob($dbkdir . "*.sql") as $filename) {
            unlink($dbkdir . $filename);
        }
    }
    //开始备份数据库
    backup_action($tables);
}
Ejemplo n.º 2
0
 /**
  * 一般文件缓存
  *
  * @param  $cache_name 缓存名称
  * @param  $content 缓存内容
  * @param  $cache_time 缓存时间,默认3600秒=1小时
  * @param  $cache_path 缓存目录,默认为/cache
  */
 public static function file_cache($cache_name, $content = '', $cache_time = 3600, $cache_path = 'cache')
 {
     $cache_path = $cache_path;
     $file_content = '';
     // 创建缓存目录,以网站根目录为起始位置
     $cache_path = $_SERVER["DOCUMENT_ROOT"] . $cache_path;
     $file_path = $cache_path . '/' . $cache_name;
     helper::mkdirs($cache_path);
     // 如果没传入内容,则读取缓存
     if ($content == '') {
         // echo('读缓存');
         if (file_exists($file_path) && time() - filemtime($file_path) < $cache_time) {
             $file_contents = file_get_contents($file_path);
             return unserialize($file_contents);
         } else {
             return 'timeout';
         }
         // 否则是强制写缓存
     } else {
         // echo('写缓存');
         $fp = fopen($file_path, 'w');
         $content = serialize($content);
         fwrite($fp, $content);
         fclose($fp);
         return unserialize($content);
     }
 }
Ejemplo n.º 3
0
    //是否生成缩略图
    $upload_config['thumbMaxWidth'] = $json_params->thumb->width;
    // 缩略图最大宽度
    $upload_config['thumbMaxHeight'] = $json_params->thumb->height;
    // 缩略图最大高度
    $upload_config['thumbPrefix'] = 'thumb_';
    // 缩略图前缀
    $upload_config['thumbPath'] = $save_path;
    // 缩略图保存路径
}
/**
 * die('<script>alert(\''.json_encode($upload_config).'\');</script>');
 */
// 判断图片保存文件夹是否存在,不存在则创建
if (!is_dir($upload_config['savePath'])) {
    helper::mkdirs($upload_config['savePath']);
}
// 开始上传
$upload = new UploadFile($upload_config);
// 返回结果
$result = array();
if (!$upload->upload()) {
    $result = $upload->getErrorMsg();
} else {
    $result = $upload->getUploadFileInfo();
}
/**
 * die('<script>alert(\''.json_encode($result).'\');</script>');
 */
// 拼装回调参数
$files = array();