From d0a2e2db25ac7b2e24dc457b0cbd661719b56cd9 Mon Sep 17 00:00:00 2001 From: Graham Cole <chckens@sucs.org> Date: Thu, 20 Nov 2008 01:04:57 +0000 Subject: [PATCH] more helpful error messages are always nice. Tell the user why their hackergotchi image was rejected --- components/options.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/options.php b/components/options.php index bdaea2c..e761267 100644 --- a/components/options.php +++ b/components/options.php @@ -154,8 +154,15 @@ function hackergotchiPath($username) { // Takes an entry from $_FILES and makes this the new hackergotchi function updateHackergotchi($fileDetails) { global $session; - if ( ((list($width, $height, $type, $attr) = @getimagesize($fileDetails['tmp_name'])) !== false) && - ($type == IMAGETYPE_PNG) && ($width <= 128) && ($height <= 128)) { + if ( ((list($width, $height, $type, $attr) = @getimagesize($fileDetails['tmp_name'])) !== false)) { + + if ($type != IMAGETYPE_PNG) { + trigger_error("Uploaded hackergotchi is not in PNG format. Please convert your image to PNG and try again.", E_USER_ERROR); + return FALSE; + } else if (($width > 128) || ($height > 128)) { + trigger_error("Uploaded hackergotchi is too large. Hackergotchis must be 128x128 pixels or smaller.", E_USER_ERROR); + return FALSE; + } $imagefilepath = hackergotchiPath($session->username); @@ -163,7 +170,7 @@ function updateHackergotchi($fileDetails) { if( move_uploaded_file($fileDetails['tmp_name'], $imagefilepath) && chmod($imagefilepath, 0644) ) { return TRUE; } - } + } // We should have returned True by now trigger_error("There was an error updating your hackergotchi. Please contact admin.", E_USER_ERROR); return FALSE; -- GitLab