<?php
if (!defined('MOD')) die("access die");
require_once(R_P . '/config/admin_options.php');
require_once(R_P . '/include/inc.editor.php');
$channelid = intval($_GET['channelid']);
$type = 1;
$fck = 0;
$bts = 1;
$file_type = 'file';
$keepName = intval($_GET['keepName']);;
$thumb = 0;
$javascript = $_GET['javascript'];
$file_id = $_GET['id'] ? $_GET['id'] : 'pic';
$sAllowExt = $ext['FILE'] .'|'. $ext['MEDIA'];

$close_thumb = 1;

@extract($channel[$channelid]);
if ($allow_upload == 0) exitupload(6);
$uptypes = explode("|", $upload_type);
$max_file_size = $upload_size;

$max_file_size = min($systemMaxUpload, $max_file_size);
$allowUploadExt = $sAllowExt ? array_intersect($uptypes, explode("|", $sAllowExt)):$uptypes;
$forbidden_upload = explode("|", $_SET['forbidden_upload']);
$allowUploadExtFlash = array();
foreach($allowUploadExt as $val) {
	if(in_array(trim($val), $forbidden_upload)) continue;
	$allowUploadExtFlash[] = "*." . trim($val);
} 
$allowUploadFileType = count($allowUploadExtFlash);

$action_url = W_P . "admin/module.php?mod=download&action=upload&channelid={$channelid}&file_type={$file_type}";

if ($_FILES["Filedata"] && $_SERVER['REQUEST_METHOD'] == 'POST') {
	InitUpload();
	DoCreateNewDir();
	require_once(R_P . '/include/class.qupload.php');	
	$upload = new qupload($sSaveDir, $allowUploadExt, $max_file_size);
	$upload->setKeepName($keepName);
	$upload_file = $upload->move();
	if($upload_file[0] > 0) exitupload($upload_file[0]);

	$real_file_name = R_P . '/' . $upload_file[1];
	$s_picurl = $web_url_name = $upload_file[1];		
	
	$arr = array('status'=>200, "msg"=>array(W_P . $web_url_name, $s_picurl));
	die(qbase::jsonencode($arr));
} else {
	include qbase::template($path . 'upload');
} 
?>