<?php
if(!defined('R_P')) exit('Access Denied');
if(!$user_info['username']) _output_upload_error("you need login");
$channelid = intval($_GET['channelid']);
if(empty($channel[$channelid])) _output_upload_error("param error");
require_once(R_P . '/include/inc.editor.php');
if(!$usergroup[$user_info['gid']]['purview']['upload']) _output_upload_error("你所在的用户组不允许上传文件");	
	$max_size = $usergroup[$user_info['gid']]['purview']['upload_size'];
	InitUpload();
	DoCreateNewDir();
	$formName = 'imgFile';
	
	if (!isset($_FILES[$formName]) || $_FILES[$formName]["error"] != 0) {
		_output_upload_error("invalid upload");
	}
	if ($usergroup[$user_info['gid']]['purview']['upload_size'] < $_FILES[$formName]["size"] / 1024) {
		_output_upload_error("上传文件最大不能超过{$max_size}KB");
	} 	
	$extname = getExt($_FILES[$formName]["name"]);
	$filename = GetRndFileName($extname);
	
	if (!in_array(strtolower($extname), explode('|', strtolower($usergroup[$user_info['gid']]['purview']['upload_ext'])))) {
		_output_upload_error("type-not-match");
	} 
	
	$web_url_name = $sSaveDir . $filename;
	$real_file_name = R_P .'/'. $web_url_name;
	if (!is_dir(R_P .'/'. $sSaveDir)) {
		qbase::createdir(R_P .'/'. $sSaveDir);
	} 

	if (false === @move_uploaded_file($_FILES[$formName]['tmp_name'], $real_file_name) && false === @copy($_FILES[$formName]['tmp_name'], $real_file_name)) _output_upload_error("move-error");	

	_output_upload_error(W_P . $web_url_name, 0);

function _output_upload_error($msg, $status = 1){
	$arr = array($status, $msg);
	die(qbase::jsonencode($arr));
}
?>
