/** * Given an upload manager with the right settings, this function performs a virus scan, and then scales and crops * it and saves it in the right place to be a "user" or "group" image. * * @param int $id user or group id * @param object $userform with imagefile upload field * @param string $dir type of entity - groups, user, ... * @return boolean success */ function save_profile_image($id, $userform, $dir = 'user') { $destination = create_profile_image_destination($id, $dir); if ($destination === false) { return false; } $filename = $userform->get_new_filename('imagefile'); $pathname = $destination . '/' . $filename; if (!$userform->save_file('imagefile', $pathname, true)) { return false; } return process_profile_image($pathname, $destination); }
/** * Try to save the given file (specified by its full path) as the * picture for the user with the given id. * * @param integer $id the internal id of the user to assign the * picture file to. * @param string $originalfile the full path of the picture file. * * @return bool */ function my_save_profile_image($id, $originalfile) { $destination = create_profile_image_destination($id, 'user'); if ($destination === false) { return false; } return process_profile_image($originalfile, $destination); }
/** * Given an upload manager with the right settings, this function performs a virus scan, and then scales and crops * it and saves it in the right place to be a "user" or "group" image. * * @param int $id user or group id * @param object $uploadmanager object referencing the image * @param string $dir type of entity - groups, user, ... * @return boolean success */ function save_profile_image($id, $uploadmanager, $dir = 'user') { if (!$uploadmanager) { return false; } $destination = create_profile_image_destination($id, $dir); if ($destination === false) { return false; } if (!$uploadmanager->save_files($destination)) { return false; } return process_profile_image($uploadmanager->get_new_filepath(), $destination); }