diff --git a/lib/avatar.php b/lib/avatar.php
index f3db07142cadd079fd800a47f3d67c1bea65c95d..dcaf81f0349a806ca188612ac3916dd6987e7a11 100644
--- a/lib/avatar.php
+++ b/lib/avatar.php
@@ -42,21 +42,21 @@ class OC_Avatar {
 	/**
 	 * @brief sets the users local avatar
 	 * @param $user string user to set the avatar for
-	 * @param $img mixed imagedata to set a new avatar, or false to delete the current avatar
+	 * @param $data mixed imagedata or path to set a new avatar, or false to delete the current avatar
 	 * @throws Exception if the provided file is not a jpg or png image
 	 * @throws Exception if the provided image is not valid, or not a square
 	 * @return true on success
 	*/
-	public static function setLocalAvatar ($user, $img) {
+	public static function setLocalAvatar ($user, $data) {
 		$view = new \OC\Files\View('/'.$user);
 
-		if ($img === false) {
+		if ($data === false) {
 			$view->unlink('avatar.jpg');
 			$view->unlink('avatar.png');
 			return true;
 		} else {
-			$img = new OC_Image($img);
-			// FIXME this always says "image/png"
+			$img = new OC_Image($data);
+			// FIXME this always says "image/png", when loading from data
 			$type = substr($img->mimeType(), -3);
 			if ($type === 'peg') { $type = 'jpg'; }
 			if ($type !== 'jpg' && $type !== 'png') {
@@ -69,7 +69,7 @@ class OC_Avatar {
 
 			$view->unlink('avatar.jpg');
 			$view->unlink('avatar.png');
-			$view->file_put_contents('avatar.'.$type, $img);
+			$view->file_put_contents('avatar.'.$type, $data);
 			return true;
 		}
 	}
diff --git a/settings/ajax/newavatar.php b/settings/ajax/newavatar.php
index 456cd84e9701bf8bb937ce5c4e1e81aa6767523e..4c8ff0c416937fe91733cd5e97e5e1428ee2cb56 100644
--- a/settings/ajax/newavatar.php
+++ b/settings/ajax/newavatar.php
@@ -5,16 +5,12 @@ OC_JSON::callCheck();
 $user = OC_User::getUser();
 
 if(isset($_POST['path'])) {
-	$path = $_POST['path'];
-	if ($path === "false") { // delete avatar
+	if ($_POST['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);
+			$path = OC::$SERVERROOT.'/data/'.$user.'/files'.$_POST['path'];
+			\OC_Avatar::setLocalAvatar($user, $path);
 			OC_JSON::success();
 		} catch (Exception $e) {
 			OC_JSON::error();