Elgg  Version 1.9
upload.php
Go to the documentation of this file.
1 <?php
6 $guid = get_input('guid');
8 
9 if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) {
10  register_error(elgg_echo('avatar:upload:fail'));
12 }
13 
14 $error = elgg_get_friendly_upload_error($_FILES['avatar']['error']);
15 if ($error) {
18 }
19 
20 $icon_sizes = elgg_get_config('icon_sizes');
21 
22 // get the images and save their file handlers into an array
23 // so we can do clean up if one fails.
24 $files = array();
25 foreach ($icon_sizes as $name => $size_info) {
26  $resized = get_resized_image_from_uploaded_file('avatar', $size_info['w'], $size_info['h'], $size_info['square'], $size_info['upscale']);
27 
28  if ($resized) {
29  //@todo Make these actual entities. See exts #348.
30  $file = new ElggFile();
31  $file->owner_guid = $guid;
32  $file->setFilename("profile/{$guid}{$name}.jpg");
33  $file->open('write');
34  $file->write($resized);
35  $file->close();
36  $files[] = $file;
37  } else {
38  // cleanup on fail
39  foreach ($files as $file) {
40  $file->delete();
41  }
42 
43  register_error(elgg_echo('avatar:resize:fail'));
45  }
46 }
47 
48 // reset crop coordinates
49 $owner->x1 = 0;
50 $owner->x2 = 0;
51 $owner->y1 = 0;
52 $owner->y2 = 0;
53 
54 $owner->icontime = time();
55 if (elgg_trigger_event('profileiconupdate', $owner->type, $owner)) {
56  system_message(elgg_echo("avatar:upload:success"));
57 
58  $view = 'river/user/default/profileiconupdate';
59  elgg_delete_river(array('subject_guid' => $owner->guid, 'view' => $view));
61  'view' => $view,
62  'action_type' => 'update',
63  'subject_guid' => $owner->guid,
64  'object_guid' => $owner->guid,
65  ));
66 }
67 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$view
Definition: crop.php:68
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $error
Definition: upload.php:14
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$owner
Definition: upload.php:7
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
elgg_get_friendly_upload_error($error_code)
Returns a human-readable message for PHP&#39;s upload error codes.
Definition: output.php:426
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_create_river_item(array $options=array())
Adds an item to the river.
Definition: river.php:37
const REFERER
Definition: elgglib.php:2162
if($error) $icon_sizes
Definition: upload.php:20
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
elgg_delete_river(array $options=array())
Delete river items.
Definition: river.php:168
get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square=false, $upscale=false)
Gets the jpeg contents of the resized version of an uploaded image (Returns false if the uploaded fil...
Definition: filestore.php:71
$files
Definition: upload.php:24
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
Definition: elgglib.php:720
$guid
Avatar upload action.
Definition: upload.php:6
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604