I am running into an issue where the uploaded image gets unset after few hours while uploading a new user picture.
Also the previous picture does not gets deleted and throws an error "File cannot be deleted because it's not a valid uri".
Here is my save function that updates the user picture programmatically.
$userimage = $form_state['values']['userimage']; //fid of the file in custom form $user_image_file = file_load($userimage); $wrapper = entity_metadata_wrapper('user', $user); // get image information $image_path = file_create_url($user_image_file->uri); $image_info = image_get_info($image_path); // create file object $file = new StdClass(); $file->uid = $uid; $file->uri = $image_path; $file->filemime = $image_info['mime_type']; $file->status = 1; // Yes! Set status to 0 in order to save temporary file. $file->filesize = $image_info['file_size']; $file->filename = drupal_basename($image_path); $file->status = FILE_STATUS_PERMANENT; $file = file_save($file); // save file to user entity $edit['picture'] = $file; user_save($user, $edit);
The image just vanishes and gives a broken url after few hours. Any directions?