summaryrefslogtreecommitdiff
path: root/actions/avatarsettings.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-01-22 12:35:09 +0100
committerEvan Prodromou <evan@controlyourself.ca>2009-01-22 12:35:09 +0100
commit6a3204d08e035812cf111e20f72bf0c7ffb4c601 (patch)
tree917164c49409c091585f40541bfd827e138b5bbc /actions/avatarsettings.php
parent904d04993c02e8707d8041e8bb0aef6a65a4d71a (diff)
Extract image management code to a helper function
Diffstat (limited to 'actions/avatarsettings.php')
-rw-r--r--actions/avatarsettings.php39
1 files changed, 6 insertions, 33 deletions
diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php
index a9b381b0a..b303fd2fd 100644
--- a/actions/avatarsettings.php
+++ b/actions/avatarsettings.php
@@ -196,37 +196,10 @@ class AvatarsettingsAction extends AccountSettingsAction
function uploadAvatar()
{
- switch ($_FILES['avatarfile']['error']) {
- case UPLOAD_ERR_OK: // success, jump out
- break;
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- $this->showForm(_('That file is too big.'));
- return;
- case UPLOAD_ERR_PARTIAL:
- @unlink($_FILES['avatarfile']['tmp_name']);
- $this->showForm(_('Partial upload.'));
- return;
- default:
- $this->showForm(_('System error uploading file.'));
- return;
- }
-
- $info = @getimagesize($_FILES['avatarfile']['tmp_name']);
-
- if (!$info) {
- @unlink($_FILES['avatarfile']['tmp_name']);
- $this->showForm(_('Not an image or corrupt file.'));
- return;
- }
-
- switch ($info[2]) {
- case IMAGETYPE_GIF:
- case IMAGETYPE_JPEG:
- case IMAGETYPE_PNG:
- break;
- default:
- $this->showForm(_('Unsupported image file format.'));
+ try {
+ $imagefile = ImageFile::fromUpload('avatarfile');
+ } catch (Exception $e) {
+ $this->showForm($e->getMessage());
return;
}
@@ -234,13 +207,13 @@ class AvatarsettingsAction extends AccountSettingsAction
$profile = $user->getProfile();
- if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
+ if ($profile->setOriginal($imagefile->filename)) {
$this->showForm(_('Avatar updated.'), true);
} else {
$this->showForm(_('Failed updating avatar.'));
}
- @unlink($_FILES['avatarfile']['tmp_name']);
+ $imagefile->unlink();
}
/**