<?php require_once 'admin/functions.php'; $req = get_param(); $db_name = @$req['db']; $db_name || ($db_name = 'default'); $table_name = @$req['table']; $opt = @$req['opt']; //读取数据 if ($opt === 'read') { $file_name = @$req['file']; if (preg_match('#\\.json$#i', $file_name)) { if (empty($table_name)) { $res_file = db_root($db_name) . "/{$file_name}"; } else { $res_file = table_root($db_name, $table_name) . "/{$file_name}"; } jsonp_nocache_exit(object_read($res_file)); } jsonp_nocache_exit(array('status' => 'error', 'error' => 'input filename error')); } //写入数据 if ($opt === 'write') { $data = @$req['data']; $table_name || ($table_name = 'default'); //后面是写入数据 if (empty($data)) { jsonp_nocache_exit(array('status' => 'error', 'error' => 'input data is empty')); } $table_root = table_root($db_name, $table_name); $schema = object_read("{$table_root}/schema.json");
<?php require_once 'functions.php'; null_exit(@$_GET['type']); defined('UPLOAD_PATH') or define('UPLOAD_PATH', db_root(WWWROOT_DIR) . '/uploads'); defined('CONFIG_PATH') or define('CONFIG_PATH', db_root(GLOBAL_DIR)); $settings = array('icon' => array('list' => 'icon_libs.json', 'max_file_size' => 1024000, 'page_size' => 16 * 16, 'thumb_x' => 32, 'thumb_y' => 32, 'prev_x' => 64, 'prev_y' => 64, 'types' => array('jpg', 'png', 'jpeg', 'gif')), 'logo' => array('list' => 'logo_libs.json', 'max_file_size' => 2048000, 'page_size' => 8 * 8, 'thumb_x' => 64, 'thumb_y' => 64, 'prev_x' => 256, 'prev_y' => 256, 'types' => array('jpg', 'png', 'jpeg', 'gif')), 'image' => array('list' => 'image_libs.json', 'max_file_size' => 4096000, 'page_size' => 8 * 8, 'thumb_x' => 128, 'thumb_y' => 128, 'prev_x' => 512, 'prev_y' => 512, 'types' => array('jpg', 'png', 'jpeg', 'gif')), 'video' => array('list' => 'video_libs.json', 'max_file_size' => 0, 'page_size' => 8 * 8, 'types' => array()), 'music' => array('list' => 'music_libs.json', 'max_file_size' => 0, 'page_size' => 8 * 8, 'types' => array()), 'file' => array('list' => 'file_libs.json', 'max_file_size' => 0, 'page_size' => 32, 'types' => array())); $setting = $settings[$_GET['type']]; $is_image = in_array($_GET['type'], array('icon', 'logo', 'image')); $cmd = isset($_GET['cmd']) ? $_GET['cmd'] : 'read'; //这是读取上传库的列表长度 if ($cmd === 'count') { $list_file = CONFIG_PATH . '/' . $setting['list']; $datas = async_read($list_file); jsonp_nocache_exit(count($datas)); } //这是读取上传库的列表,全部读取,仅仅ID if ($cmd === 'list') { $startindex = isset($_GET['startindex']) ? intval($_GET['startindex']) : null; $endindex = isset($_GET['endindex']) ? intval($_GET['endindex']) : null; $pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : null; $list_file = CONFIG_PATH . '/' . $setting['list']; $datas = async_read($list_file); if (empty($endindex) or empty($pagesize)) { jsonp_nocache_exit($datas); } if (empty($startindex)) { $startindex = 0; } $count = count($datas); $index = $startindex * $pagesize;
function table_root($db_name, $table_name) { return db_root($db_name) . "/{$table_name}"; }
function create_database_exit($req) { $db_root = db_root($req['name']); if (file_exists($db_root)) { jsonp_nocache_exit(array('status' => 'error', 'error' => 'The request database already exists.', 'ori_cmd' => $req)); } else { mkdir($db_root, 0744); } $db_schema = "{$db_root}/schema.json"; if (file_exists($db_schema)) { unlink($db_schema); } $caption = array(); $caption['title'] = $req['title']; $caption['content'] = $req['content']; $caption['key'] = $req['key']; $caption['image'] = $req['image']; $schema = array(); $schema['caption'] = $caption; object_save($db_schema, $schema); jsonp_nocache_exit(array('status' => 'ok')); }