<?php

if(is_array($_FILES)) {

	$session = get_session_details();
    $loggeduser = (object)$session->userdetails;
    $userid = $loggeduser->userid;

	if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
	$sourcePath = $_FILES['userImage']['tmp_name'];

	$targetPath = "assets/avatars/".$_FILES['userImage']['name'];

	mysql_query("UPDATE `users` SET `avatar`='$targetPath' WHERE  `user_id`=$userid;");

		if(move_uploaded_file($sourcePath,$targetPath)) {
			echo '<img src="' .base_url(). '' .$targetPath. '" width="100px" height="100px" />';
		}
	}
}
?>