Elgg  Version 6.1
upload.php
Go to the documentation of this file.
1 <?php
6 $guid = (int) get_input('guid');
8 if (!$owner || !$owner->canEdit()) {
9  return elgg_error_response(elgg_echo('avatar:upload:fail'));
10 }
11 
12 if (get_input('avatar_remove')) {
13  if (!$owner->deleteIcon()) {
14  return elgg_error_response(elgg_echo('avatar:remove:fail'));
15  }
16 
17  return elgg_ok_response('', elgg_echo('avatar:remove:success'));
18 }
19 
20 /* @var $avatar \Symfony\Component\HttpFoundation\File\UploadedFile */
21 $avatar = elgg_get_uploaded_file('avatar', false);
22 if (!empty($avatar) && !$avatar->isValid()) {
24 
26 } elseif (empty($avatar)) {
27  return elgg_error_response(elgg_echo('avatar:upload:fail'));
28 }
29 
30 if (!$owner->saveIconFromUploadedFile('avatar')) {
31  return elgg_error_response(elgg_echo('avatar:resize:fail'));
32 }
33 
34 if (!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) {
35  return elgg_error_response();
36 }
37 
38 // River
39 $view = 'river/user/default/profileiconupdate';
40 
41 // remove old river items
43  'subject_guid' => $owner->guid,
44  'view' => $view,
45  'limit' => false,
46 ]);
47 
48 // create new river entry
50  'view' => $view,
51  'action_type' => 'update',
52  'subject_guid' => $owner->guid,
53  'object_guid' => $owner->guid,
54 ]);
55 
56 return elgg_ok_response('', elgg_echo('avatar:upload:success'), $owner->getURL());
$owner
Definition: upload.php:7
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_get_uploaded_file(string $input_name, bool $check_for_validity=true)
Returns a single valid uploaded file object.
Definition: filestore.php:156
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:135
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_create_river_item(array $options=[])
Elgg river.
Definition: river.php:28
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
$error
Bad request error.
Definition: 400.php:6
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
if(!$owner||!$owner->canEdit()) if(get_input('avatar_remove')) $avatar
Definition: upload.php:21
elgg_get_friendly_upload_error(int $error_code)
Returns a human-readable message for PHP&#39;s upload error codes.
Definition: output.php:272
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_trigger_event(string $event, string $type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
Definition: events.php:102
$guid
Avatar upload action.
Definition: upload.php:6