1.config.js文件里添加图片上传处理php文件
CKEDITOR.editorConfig = function( config )
{
//使用相对路径时,当前位置是调用ckeditor.js这个html文件的位置
config.filebrowserImageUploadUrl = './extends/ckeditor/upload.php?type=img';
config.filebrowserFlashUploadUrl = './extends/ckeditor/upload.php?type=flash';
};
2.在ckeditor文件夹里建立upload.php文件,按需配置
/**
* upload.php ckeditor图片上传处理
*/
header("content-Type: text/html; charset=utf-8");
$config = array();
$config['type'] = array("flash", "img"); //上传允许type值
$config['img'] = array("jpg", "bmp", "gif" , "png"); //img允许后缀
$config['flash'] = array("flv", "swf"); //flash允许后缀
$config['flash\_size'] = 200; //上传flash大小上限 单位:KB
$config['img\_size'] = 500; //上传img大小上限 单位:KB
$config['message'] = "success"; //上传成功后显示的消息,若为空则不显示
$config['name'] = mktime() . rand(0 , 1000); //上传后的文件命名规则 这里以unix时间戳来命名
$config['flash\_dir'] = "upload"; //上传flash文件地址 相对于网站根目录的路径 后面不加"/"
$config['img\_dir'] = "upload"; //上传img文件地址 相对于网站根目录的路径 后面不加"/"
$config['thisPhpDir'] = "../.."; //此php文件相对于网站根目录的路径 后面不加"/"
//文件上传
uploadfile();
function uploadfile()
{
global $config;
//判断是否是非法调用
if (empty($\_GET['CKEditorFuncNum']))
mkhtml(1, "", "错误的功能调用请求");
$fn = $\_GET['CKEditorFuncNum'];
if (!in\_array($\_GET['type'], $config['type']))
mkhtml(1, "", "错误的文件调用请求");
$type = $\_GET['type'];
if (is\_uploaded\_file($\_FILES['upload']['tmp\_name'])) {
//判断上传文件是否允许
$filearr = pathinfo($\_FILES['upload']['name']);
$filetype = $filearr["extension"];
if (!in\_array($filetype, $config[$type]))
mkhtml($fn, "", "错误的文件类型!");
//判断文件大小是否符合要求
if ($\_FILES['upload']['size']>$config[$type . "\_size"]*1024)
mkhtml($fn, "", "上传的文件不能超过" . $config[$type . "\_size"] . "KB!");
$file\_htmlDir = $config[$type . "\_dir"] . "/" . $config['name'] . "." . $filetype;//上传文件后返回给html的图片路径
$file\_php2Dir = $config['thisPhpDir'] . "/" . $file\_htmlDir;//此php文件相到图片存放文件夹的路径
if (move\_uploaded\_file($\_FILES['upload']['tmp\_name'], $file\_php2Dir)) {
mkhtml($fn, $file\_htmlDir, $config['message']);
}
else {
mkhtml($fn, "", "文件上传失败,请检查上传目录设置和目录读写权限");
}
}
}
function mkhtml($fn, $fileurl, $message)
{
$str = '';
exit($str);
}