summaryrefslogtreecommitdiffstats
path: root/settings/ajax/newavatar.php
blob: 456cd84e9701bf8bb937ce5c4e1e81aa6767523e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

OC_JSON::checkLoggedIn();
OC_JSON::callCheck();
$user = OC_User::getUser();

if(isset($_POST['path'])) {
	$path = $_POST['path'];
	if ($path === "false") { // delete avatar
		\OC_Avatar::setLocalAvatar($user, false);
	} else { // select an image from own files
		$view = new \OC\Files\View('/'.$user.'/files');
		$img = $view->file_get_contents($path);

		$type = substr($path, -3);
		try {
			\OC_Avatar::setLocalAvatar($user, $img);
			OC_JSON::success();
		} catch (Exception $e) {
			OC_JSON::error();
		}
	}
} elseif (isset($_POST['image'])) { // upload a new image
	\OC_Avatar::setLocalAvatar($user, $_POST['image']);
	OC_JSON::success();
} else {
	OC_JSON::error();
}