<?php
require dirname(__FILE__) . '/../jxcms/common.php';
$uid = abs(intval($_GET['uid']));
$fullUid = sprintf("%09d", $uid);
$avatar = C('uploaddir', 0, 'attachment') . '/avatar/' . substr($fullUid, 0, 3) . '/' . substr($fullUid, 3, 2) . '/' . substr($fullUid, 5, 2) . '/';
if ($uid) {
	if ($_GET['action'] == 'upload') {
		$rs = array();
		if ($uid == get_cookie('userid') || defined('IN_ADMIN')) {
			$input = file_get_contents('php://input');
			$data = explode('--------------------', $input);
			$avatar = JXCMS_ROOT . $avatar;
			FileUtil :: create($avatar);
			$avatar .= $uid . '_avatar_';
			@file_put_contents($avatar . 'b.jpg', $data[0]);
			@file_put_contents($avatar . 'm.jpg', $data[1]);
			@file_put_contents($avatar . 's.jpg', $data[2]);
			$rs['status'] = 1;
		} else $rs['status'] = -2;
	} else {
		$avatar = Tag::avatar($uid, R('size'));
		header('Location: ' . $avatar);
		exit;
	}
} else $rs['status'] = -1;
echo json_encode($rs);
?>
