<?php
if (!defined('MOD')) die("access die");
require_once(R_P."/include/inc.editor.php");
$channelid  = intval( $_GET['channelid']);
$img = urldecode($_GET['img']);
InitUpload();
DoCreateNewDir();
$SaveFileType = qbase::fileext($img);
$SaveFileName = GetRndFileName($SaveFileType);
$data = array('status'=>200, 'img'=>$img);
if (SaveRemoteFile($SaveFileName, $img) === true) {
	$data['url'] = $sSaveDir.$SaveFileName;
}else{
	$data['status'] = 404;
}
echo qbase::xmlPrint(qbase::jsonencode($data));
function SaveRemoteFile($s_LocalFileName, $s_RemoteFileUrl) 
{
	$cont = qbase::load($s_RemoteFileUrl);
	if(!$cont) return false;
	$filename = R_P .'/'. $GLOBALS["sSaveDir"].$s_LocalFileName;
	qbase::writetofile($filename, $cont);
	clearstatcache();
	$info = @getimagesize($filename);
	if($info === false) return false;
	return true;
}
?>