Elgg  Version 3.0
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'));
get_user($guid)
Get a user object from a GUID.
Definition: users.php:40
$owner
Definition: upload.php:7
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:220
elgg_create_river_item(array $options=[])
Adds an item to the river.
Definition: river.php:33
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_get_friendly_upload_error($error_code)
Returns a human-readable message for PHP&#39;s upload error codes.
Definition: output.php:336
elgg_get_uploaded_file($input_name, $check_for_validity=true)
Returns a single valid uploaded file object.
Definition: filestore.php:396
$error
Bad request error.
Definition: 400.php:6
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
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_error_response($error= '', $forward_url=REFERRER, $status_code=ELGG_HTTP_OK)
Prepare an error response to be returned by a page or an action handler.
if(!$owner||!$owner->canEdit()) if(get_input('avatar_remove')) $avatar
Definition: upload.php:21
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif(is_callable([$item, 'getType']))
Definition: item.php:39
elgg_ok_response($content= '', $message= '', $forward_url=null, $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_trigger_event($event, $object_type, $object=null)
Definition: elgglib.php:513
$guid
Avatar upload action.
Definition: upload.php:6