2

Is there a way that I can remove/delete user profile picture through programing? or How can i override existing image with my new one?

3
  • 2
    Is there a reason you can't use the UI? If you could explain more about what you're trying to accomplish that would be helpful
    – Clive
    Aug 28, 2013 at 14:08
  • Yes because i have custom Layout for user profile page. for that I user my custom tpl file other than user--profile.tpl.php Aug 28, 2013 at 14:16
  • have you investigated api.drupal.org/api/drupal/modules!user!user-picture.tpl.php/7 ?
    – Jimajamma
    Aug 28, 2013 at 14:35

1 Answer 1

1

use code below in hook_user_delete($account)

// Load user by using user id
$user = user_load($uid);
// Get file id of profile photo
$fid = $user->picture->fid;
// Load the file object
$file = file_load($fid);
// delete profile photo from.
file_delete($file);
// Unset the image object (my case it's 'picture')
unset($user->picture);
// Save the user
user_save($user);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.