借鉴了ueditor自带的php代码,和ot中的相关代码。
此代码已发布到我的csdn当中 display();
}
/**
* 用于百度ueditor
* 其中ue_config在config文件中定义
*/
public function manager() {
date_default_timezone_set(asia/chongqing);
$config = json_decode(preg_replace(/\/\*[\s\s]+?\*\//, , file_get_contents(c('ue_config'))), true);
$action = $_get['action'];
switch ($action) {
case 'config' :
$result = $config;
break;
case 'listfile' :
case 'listimage' :
$result = $this -> lists($config, $action);
break;
/* 上传图片 */
case 'uploadimage' :
/* 上传涂鸦 */
case 'uploadscrawl' :
$config = array('maxsize' => $conifg['imagemaxsize'], 'rootpath' => c('upload_path'), 'savepath' => 'images/', 'savename' => array('uniqid', ''), 'exts' => $conifg['imageallowfiles'], 'autosub' => true, 'subname' => array('date', 'ymd'), );
$result = $this -> up($config);
break;
/* 上传视频 */
case 'uploadvideo' :
$config = array('maxsize' => $conifg['videomaxsize'], 'rootpath' => c('upload_path'), 'savepath' => 'videos/', 'savename' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg', 'zip', 'doc', 'pdf'), 'autosub' => true, 'subname' => array('date', 'ymd'), );
$result = $this -> up($config);
break;
/* 上传文件 */
case 'uploadfile' :
default :
$config = array('maxsize' => $conifg['filemaxsize'], 'rootpath' => c('upload_path'), 'savepath' => 'files/', 'savename' => array('uniqid', ''), 'exts' => $conifg['filemanagerallowfilesarray'], 'autosub' => true, 'subname' => array('date', 'ymd'), );
$result = $this -> up($config);
break;
}
/* 输出结果 */
if (isset($_get[callback])) {
if (preg_match(/^[\w_]+$/, $_get[callback])) {
$this -> ajaxreturn($result, 'json');
} else {
$tmp = array('state' => 'callback参数不合法');
$this -> ajaxreturn($tmp, 'json');
}
} else {
//echo $result;
$this -> ajaxreturn($result, 'json');
}
}
/**
* 用于百度编辑器上传功能
*/
public function up($config) {
//todo:删除不删除?
@ini_set('upload_max_filesize', '20m');
$picture = d('picture');
$file_driver = c('picture_upload_driver');
$info = $picture -> upload($_files, $config, c('picture_upload_driver'), c(upload_{$file_driver}_config));
if ($info) {
if ($info['upfile']['url'] == ) {
return array('url' => __root__ . $info['upfile']['path'], 'title' => htmlspecialchars($_post['pictitle'], ent_quotes), 'original' => $info['upfile']['name'], 'state' => 'success');
} else {
return array('url' => $info['upfile']['url'], 'title' => htmlspecialchars($_post['pictitle'], ent_quotes), 'original' => $info['upfile']['name'], 'state' => 'success');
}
} else {
return array('state' => $picture -> geterror());
//获取失败信息
}
}
/**
*百度编辑器列出本地服务器上传目录
*
*
**/
public function lists($config, $type) {
switch ($type) {
case 'listfile' :
$allowfiles = $config['filemanagerallowfiles'];
$listsize = $config['filemanagerlistsize'];
$path = $config['filemanagerlistpath'];
break;
default :
$allowfiles = $config['imagemanagerallowfiles'];
$listsize = $config['imagemanagerlistsize'];
$path = $config['imagemanagerlistpath'];
break;
}
$allowfiles = substr(str_replace(., |, join(, $allowfiles)), 1);
/* 获取参数 */
$size = isset($_get['size']) ? htmlspecialchars($_get['size']) : $listsize;
$start = isset($_get['start']) ? htmlspecialchars($_get['start']) : 0;
$end = $start + $size;
/* 获取文件列表 */
$path = doc_root . c('upload_path');
$files = $this -> getfiles($path, $allowfiles);
if (!count($files)) {
return array(state => no match file, list => array(), start => $start, total => count($files));
}
/* 获取指定范围的列表 */
$len = count($files);
for ($i = min($end, $len) - 1, $list = array(); $i = 0 && $i >= $start; $i--) {
$list[] = $files[$i];
}
$result = array(state => success, list => $list, start => $start, total => count($files));
return $result;
}
/**
* 获取本地文件
*/
function getfiles($path, $allowfiles, &$files = array()) {
if (!is_dir($path)) {
exit('e1:path is wrong ' . $path);
return null;
}
if (substr($path, strlen($path) - 1) != '/')
$path .= '/';
$handle = opendir($path);
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$path2 = $path . $file;
if (is_dir($path2)) {
$this -> getfiles($path2, $allowfiles, $files);
} else {
if (preg_match(/\.( . $allowfiles . )$/i, $file)) {
$files[] = array('url' => substr($path2, strlen($_server['document_root'])), 'mtime' => filemtime($path2));
}
}
}
}
return $files;
}
/**
* 上传图片
* @author huajie
*/
public function uploadpicture() {
/* 返回标准数据 */
$return = array('status' => 1, 'info' => '上传成功', 'data' => '');
/* 调用文件上传组件上传文件 */
$picture = d('picture');
$file_driver = c('picture_upload_driver');
$info = $picture -> upload($_files, c('picture_upload'), c('picture_upload_driver'), c(upload_{$file_driver}_config));
//todo:上传到远程服务器
/* 记录图片信息 */
if ($info) {
$return['status'] = 1;
$return = array_merge($info['download'], $return);
} else {
$return['status'] = 0;
$return['info'] = $picture -> geterror();
}
/* 返回json数据 */
$this -> ajaxreturn($return);
}
}
ad:真正免费,域名+虚机+企业邮箱=0元
