<?php
header("Content-type:text/html;charset=utf-8");  

$config = array();
$config['type'] = array("flash","img"); 
$config['img'] = array("jpg","png","gif","bmp");
$config['flash'] = array("flv","swf"); 
$config['flash_size'] = 200; 
$config['img_size'] = 500; 
$config['success'] = "上传成功"; 
$config['name'] = mktime(); 
$config['root'] = "../../sysmsgs/images/";

function returnscript($fn,$fileurl,$message) {
	$str='<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$fn.', \''.$fileurl.'\', \''.$message.'\');</script>';
	exit($str);
}

function uploadfile() {
	global $config;

	if (empty($_GET['CKEditorFuncNum']))
		returnscript(1, "", "错误的请求");

	$fn = $_GET['CKEditorFuncNum'];
	$type = strtolower($_GET['type']);

	if(!in_array($type, $config['type']))
		returnscript(1,"","错误的请求");

	if(is_uploaded_file($_FILES['upload']['tmp_name'])) {
	   $filearr = pathinfo($_FILES['upload']['name']);
	   $filetype = $filearr["extension"];

	   if (!in_array($filetype, $config[$type])) 
			returnscript($fn, "", "不支持该文件类型！");

	   if ($_FILES['upload']['size'] > $config[$type."_size"] * 1024)
			returnscript($fn, "", "上传的文件不能超过" . $config[$type."_size"] . "KB！");

	   if (move_uploaded_file($_FILES['upload']['tmp_name'], $config['root'] . $config['name'] . "." . $filetype)) {
			returnscript($fn, $config['root'] . $config['name'] . "." . $filetype, $config['success']);
	   } else {
			returnscript($fn, "", "文件上传失败！");
	   }
	}
}

uploadfile();
?>