Drupal user picture deleted automatically
Sometimes you could be in a fury when user picture gets deleted automatically with nothing being noticed as strange. Even this thread 935592 might not help you. Then you have come to right place. Ofcourse the culprit could be your call to user_save() somewhere. The actual issue might be, you are passing global user object instead of full account object. The first param of user_save() should be a full account object, while global user does not have all the data of account object. In this case $account->picture is an object while $user->picture is just an integer, fid (File id) of the image file. So while trying to save, your picture association with the user account gets broken. The reason can be understood by looking at the user_save() source code. The method checks for
empty($account->picture->fid)
While using $user, this condition becomes false (we only have $account->picture not $account->picture->fid) and user picuter is removed.
So make sure you call like this,
global $user
$account = account_load($user->uid);
/*Some operations with $account object*/
user_save($account, $edit); /*NOT user_save($user, $edit)*/