function image_upload_function($field_name = "", $upload_path = './', $width = 0, $height = 0, $max_width = 800, $max_height = 800, $max_size = 500, $maintain_ratio = TRUE, $encrypt_name = TRUE, $create_thumb = FALSE, $thumb_width = 280, $thumb_height = 160, $thumb_maintain_ration = TRUE, $is_watermark = FALSE)
 {
     $ci =& get_instance();
     $return_arr = array(true, "error_msg" => "Undefined error!");
     $config['upload_path'] = $upload_path;
     $config['allowed_types'] = 'gif|jpg|png|jpeg';
     $config['max_size'] = $max_size;
     $config['max_width'] = $max_width;
     $config['max_height'] = $max_height;
     $config['encrypt_name'] = $encrypt_name;
     $config['remove_spaces'] = TRUE;
     $ci->load->library('upload', $config);
     if (!$ci->upload->do_upload($field_name)) {
         $return_arr["error_msg"] = $ci->upload->display_errors();
     } else {
         $upload_data = $ci->upload->data();
         //create thumbnail in same folder with thumb_ prefix
         if ($create_thumb) {
             create_image_thumb($upload_data["full_path"], $thumb_width, $thumb_height, $thumb_maintain_ration);
         }
         //End
         if ($is_watermark) {
             create_watermark($upload_data["full_path"]);
         }
         $return_arr = array(false, 'upload_data' => $upload_data);
     }
     return $return_arr;
 }
示例#2
0
 /**
  * Loads the data for the user from the database
  * This will not return a "group" (even though groups are
  * stored in the Users table)
  *
  * @param String $style (optional - default 'long') may be 'short' or 'long'
  * @return User object (this) (or Error object)
  */
 function load($style = 'long')
 {
     global $DB, $USER, $CFG, $ERROR, $HUB_FLM, $HUB_SQL, $HUB_CACHE;
     $this->style = $style;
     if (isset($HUB_CACHE)) {
         $cachedused = $HUB_CACHE->getObjData($this->userid . $style);
         if ($cachedused !== FALSE) {
             return $cachedused;
         }
     }
     $params = array();
     $params[0] = $this->userid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_USER_SELECT, $params);
     if ($resArray !== false) {
         $count = count($resArray);
         if ($count == 0) {
             $ERROR = new error();
             $ERROR->createUserNotFoundError($this->userid);
             return $ERROR;
         } else {
             for ($i = 0; $i < $count; $i++) {
                 $array = $resArray[$i];
                 $this->name = stripslashes($array['Name']);
                 $this->isgroup = $array['IsGroup'];
                 $this->creationdate = $array['CreationDate'];
                 $this->testgroup = $array['TestGroup'];
                 if ($array['Photo']) {
                     //set user photo and thumb the thumb creation is done during registration
                     $originalphotopath = $HUB_FLM->createUploadsDirPath($this->userid . "/" . stripslashes($array['Photo']));
                     if (file_exists($originalphotopath)) {
                         $this->photo = $HUB_FLM->getUploadsWebPath($this->userid . "/" . stripslashes($array['Photo']));
                         $this->thumb = $HUB_FLM->getUploadsWebPath($this->userid . "/" . str_replace('.', '_thumb.', stripslashes($array['Photo'])));
                         if (!file_exists($this->thumb)) {
                             create_image_thumb($array['Photo'], $CFG->IMAGE_THUMB_WIDTH, $this->userid);
                         }
                     } else {
                         //if the file does not exists how to get it from a upper level? change it to
                         //if file doesnot exists directly using default photo
                         if ($this->isgroup == "Y") {
                             $this->photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_GROUP_PHOTO);
                             $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_GROUP_PHOTO)));
                         } else {
                             $this->photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_USER_PHOTO);
                             $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_USER_PHOTO)));
                         }
                     }
                 } else {
                     if ($this->isgroup == "Y") {
                         $this->photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_GROUP_PHOTO);
                         $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_GROUP_PHOTO)));
                     } else {
                         $this->photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_USER_PHOTO);
                         $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_USER_PHOTO)));
                     }
                 }
                 $this->lastlogin = $array['LastLogin'];
                 $this->followsendemail = $array['FollowSendEmail'];
                 $this->followruninterval = $array['FollowRunInterval'];
                 $this->followlastrun = $array['FollowLastRun'];
                 if (isset($array['Newsletter'])) {
                     $this->newsletter = $array['Newsletter'];
                 }
                 if (isset($array['RecentActivitiesEmail'])) {
                     $this->recentactivitiesemail = $array['RecentActivitiesEmail'];
                 }
                 if (isset($array['CurrentStatus'])) {
                     $this->status = $array['CurrentStatus'];
                 }
                 if ($style == 'long') {
                     $this->description = stripslashes($array['Description']);
                     $this->modificationdate = $array['ModificationDate'];
                     $this->privatedata = $array['Private'];
                     $this->isadmin = $array['IsAdministrator'];
                     $this->authtype = $array['AuthType'];
                     $this->password = $array['Password'];
                     $this->website = $array['Website'];
                     $this->email = $array['Email'];
                     if (isset($array['Interest'])) {
                         $this->interest = $array['Interest'];
                     }
                     if (isset($array['LocationText'])) {
                         $this->location = $array['LocationText'];
                     } else {
                         $this->location = "";
                     }
                     if (isset($array['LocationCountry'])) {
                         $cs = getCountryList();
                         $this->countrycode = $array['LocationCountry'];
                         if (isset($cs[$array['LocationCountry']])) {
                             $this->country = $cs[$array['LocationCountry']];
                         }
                     } else {
                         $this->countrycode = "";
                     }
                     if (isset($array['LocationLat'])) {
                         $this->locationlat = $array['LocationLat'];
                     }
                     if (isset($array['LocationLng'])) {
                         $this->locationlng = $array['LocationLng'];
                     }
                     // REPAIR MISSING COODINATES
                     if (isset($this->location) && isset($this->countrycode) && $this->location != "" && $this->countrycode != "" && ((!isset($array['LocationLng']) || $array['LocationLng'] == "") && (!isset($array['LocationLat']) || $array['LocationLat'] == ""))) {
                         $coords = geoCode($this->location, $this->countrycode);
                         if ($coords["lat"] != "" && $coords["lng"] != "") {
                             $params = array();
                             $params[0] = $coords["lat"];
                             $params[1] = $coords["lng"];
                             $params[2] = $this->userid;
                             $res = $DB->insert($HUB_SQL->DATAMODEL_USER_LATLONG_UPDATE, $params);
                             $this->locationlat = $coords["lat"];
                             $this->locationlng = $coords["lng"];
                         }
                     }
                 }
             }
         }
     } else {
         return database_error();
     }
     //now add in any tags
     if ($style == 'long') {
         $params = array();
         $params[0] = $this->userid;
         $resArray = $DB->select($HUB_SQL->DATAMODEL_USER_TAGS, $params);
         if ($resArray !== false) {
             $count = count($resArray);
             if ($count > 0) {
                 $this->tags = array();
                 for ($i = 0; $i < $count; $i++) {
                     $array = $resArray[$i];
                     $tag = new Tag(trim($array['TagID']));
                     array_push($this->tags, $tag->load());
                 }
             }
         } else {
             return database_error();
         }
     }
     //load the current user's following for this user if any
     $this->userfollow = "N";
     $currentuser = '';
     if (isset($USER->userid)) {
         $currentuser = $USER->userid;
     }
     $params = array();
     $params[0] = $currentuser;
     $params[1] = $this->userid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_USER_FOLLOW, $params);
     if ($resArray !== false) {
         $count = count($resArray);
         if ($count > 0) {
             $this->userfollow = "Y";
         }
     } else {
         return database_error();
     }
     if (isset($HUB_CACHE)) {
         $HUB_CACHE->setObjData($this->userid . $style, $this, $CFG->CACHE_DEFAULT_TIMEOUT);
     }
     return $this;
 }
示例#3
0
 /**
  * Loads the data for the node from the database
  *
  * @param String $style (optional - default 'long') may be 'short' or 'long' or 'mini' or 'full' or 'shortactivity' (mini used for graphs)
  * 'mini' include the base information like name, description, role, user, private, creation and modifications dates, connectedness, image, thumb.
  * 'short' includes 'mini' plus address information, start and end date, otherconnections, userfollow.
  * 'long' includes 'short' and associated website objects, tag objects, group onjects, votes, view counts and extra properties.
  * 'full' includes 'long' and all activity and voting data. This is likely to be very heavy. Use wisely.
  * 'shortactivity' includes 'short' plus the activity and voting data.
  * 'cif' just what is needed for cif.
  * @return Node object (this)
  */
 function load($style = 'long')
 {
     global $DB, $CFG, $USER, $ERROR, $HUB_FLM, $HUB_SQL;
     try {
         $this->canview();
     } catch (Exception $e) {
         return access_denied_error();
     }
     $this->style = $style;
     $params = array();
     $params[0] = $this->nodeid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_SELECT, $params);
     if ($resArray !== false) {
         $count = count($resArray);
         if ($count == 0) {
             $ERROR = new error();
             $ERROR->createNodeNotFoundError($this->nodeid);
             return $ERROR;
         } else {
             for ($i = 0; $i < $count; $i++) {
                 $array = $resArray[$i];
                 $this->name = stripslashes(trim($array['Name']));
                 $this->creationdate = $array['CreationDate'];
                 $this->modificationdate = $array['ModificationDate'];
                 if (isset($array['NodeTypeID'])) {
                     $this->role = new Role($array['NodeTypeID']);
                     $this->role = $this->role->load();
                 }
                 if (trim($array['Description']) != "") {
                     $this->hasdesc = true;
                 }
                 if ($style == 'long' || $style == 'cif') {
                     $this->description = stripslashes(trim($array['Description']));
                 }
                 $this->users = array();
                 if ($style == 'cif') {
                     //CIF does not need the whole user info at present
                     // or just userid at this level?
                     $this->users[0] = new User($array['UserID']);
                 } else {
                     $maps = getMapsForNode($this->nodeid, 0, 0);
                     $this->mapcount = $maps->totalno;
                     $this->connectedness = $array['connectedness'];
                     $this->private = $array['Private'];
                     $this->users[0] = getUser($array['UserID'], $style);
                     if ($array['Image']) {
                         $this->filename = $array['Image'];
                         $imagedir = $HUB_FLM->getUploadsNodeDir($this->nodeid, $array['UserID']);
                         $originalphotopath = $HUB_FLM->createUploadsDirPath($imagedir . "/" . stripslashes($array['Image']));
                         if (file_exists($originalphotopath)) {
                             $this->image = $HUB_FLM->getUploadsWebPath($imagedir . "/" . stripslashes($array['Image']));
                             $this->thumb = $HUB_FLM->getUploadsWebPath($imagedir . "/" . str_replace('.', '_thumb.', stripslashes($array['Image'])));
                             if (!file_exists($this->thumb)) {
                                 create_image_thumb($array['Image'], $CFG->IMAGE_THUMB_WIDTH, $imagedir);
                             }
                         } else {
                             if ($this->role->name == 'Map') {
                                 $this->image = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_ISSUE_PHOTO);
                                 $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_ISSUE_PHOTO)));
                             }
                         }
                     } else {
                         if ($this->role->name == 'Map') {
                             $this->image = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_ISSUE_PHOTO);
                             $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_ISSUE_PHOTO)));
                         }
                     }
                     //if(isset($array['Image'])){
                     //    $this->imageurlid = $array['Image'];
                     //}
                     //if(isset($array['ImageThumbnail'])){
                     //    $this->thum = $array['ImageThumbnail'];
                     //}
                     if ($style != 'mini') {
                         if (isset($array['StartDate']) && $array['StartDate'] != 0) {
                             $this->startdatetime = $array['StartDate'];
                         }
                         if (isset($array['EndDate']) && $array['EndDate'] != 0) {
                             $this->enddatetime = $array['EndDate'];
                         }
                         if (isset($array['LocationText'])) {
                             $this->location = $array['LocationText'];
                         } else {
                             $this->location = '';
                         }
                         if (isset($array['LocationCountry'])) {
                             $cs = getCountryList();
                             $this->countrycode = $array['LocationCountry'];
                             if (isset($cs[$array['LocationCountry']])) {
                                 $this->country = $cs[$array['LocationCountry']];
                             }
                         }
                         if (isset($array['LocationLat'])) {
                             $this->locationlat = $array['LocationLat'];
                         }
                         if (isset($array['LocationLng'])) {
                             $this->locationlng = $array['LocationLng'];
                         }
                         if (isset($array['LocationAddress1'])) {
                             $this->locationaddress1 = $array['LocationAddress1'];
                         }
                         if (isset($array['LocationAddress2'])) {
                             $this->locationaddress2 = $array['LocationAddress2'];
                         }
                         if (isset($array['LocationPostCode'])) {
                             $this->locationpostcode = $array['LocationPostCode'];
                         }
                         if (isset($array['AdditionalIdentifier'])) {
                             $this->identifier = $array['AdditionalIdentifier'];
                         }
                         if (isset($array['CurrentStatus'])) {
                             $this->status = $array['CurrentStatus'];
                         }
                     }
                 }
             }
         }
     } else {
         return database_error();
     }
     $currentuser = '';
     if (isset($USER->userid)) {
         $currentuser = $USER->userid;
     }
     if ($style != 'mini' && $style != 'cif') {
         $params = array();
         $params[0] = $this->nodeid;
         $params[1] = $this->nodeid;
         $params[2] = $currentuser;
         $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_EXTERNAL_CONNECTIONS, $params);
         if ($resArray !== false) {
             if (count($resArray) > 0) {
                 $this->otheruserconnections = $resArray[0]['connectedness'];
             } else {
                 $this->otheruserconnections = 0;
             }
         }
         $this->userfollow = "N";
         //load the current user's following status for this node if any
         $params = array();
         $params[0] = $currentuser;
         $params[1] = $this->nodeid;
         $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_USER_FOLLOW, $params);
         if ($resArray !== false) {
             if (count($resArray) > 0) {
                 $this->userfollow = "Y";
             }
         }
     }
     if ($style == 'long' || $style == 'full' || $style == 'cif') {
         $this->loadWebsites($style);
     }
     if ($style == 'long' || $style == 'full') {
         $this->loadTags();
         $this->loadGroups();
         $this->loadVotes();
         $this->loadProperties();
         $this->loadViewCount();
     }
     if ($style == 'full' || $style == 'shortactivity') {
         $this->activity = getAllNodeActivity($this->nodeid, 0, 0, -1);
         $this->votes = getVotes($this->nodeid);
     }
     //load comments, pro count and con count if Solution.
     /*if ($this->role->name == "Solution") {
     			$this->haschildren = 'N';
     			$conSetKids = getConnectionsByNode($this->nodeid,0,0,'date','ASC', 'all', '', 'Pro,Con,Comment');
     			if (!$conSetKids instanceof Error) {
     				if ($conSetKids->totalno > 0) {
     					$this->haschildren = 'Y';
     				}
     			} else {
     				return database_error();
     			}
     		}*/
     return $this;
 }
示例#4
0
 /**
  * Loads the data for the group from the database
  *
  * @return Group object (this)
  */
 function load()
 {
     global $DB, $CFG, $HUB_FLM, $HUB_SQL, $LNG;
     $params = array();
     $params[0] = $this->groupid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_GROUP_SELECT, $params);
     if ($resArray !== false) {
         $count = count($resArray);
         if ($count == 0) {
             global $ERROR;
             $ERROR = new Error();
             $ERROR->createGroupNotFoundError($this->groupid);
             return $ERROR;
         }
         for ($i = 0; $i < $count; $i++) {
             $array = $resArray[$i];
             $this->name = stripslashes($array['Name']);
             $this->description = stripslashes($array['Description']);
             $this->website = stripslashes($array['Website']);
             $this->isopenjoining = $array['IsOpenJoining'];
             if ($array['Photo']) {
                 //set user photo and thumb the thumb creation is done during registration
                 $originalphotopath = $HUB_FLM->createUploadsDirPath($this->groupid . "/" . stripslashes($array['Photo']));
                 if (file_exists($originalphotopath)) {
                     $this->photo = $HUB_FLM->getUploadsWebPath($this->groupid . "/" . stripslashes($array['Photo']));
                     $this->thumb = $HUB_FLM->getUploadsWebPath($this->groupid . "/" . str_replace('.', '_thumb.', stripslashes($array['Photo'])));
                     if (!file_exists($this->thumb)) {
                         create_image_thumb($array['Photo'], $CFG->IMAGE_THUMB_WIDTH, $this->groupid);
                     }
                 } else {
                     //if the file does not exists how to get it from a upper level? change it to
                     //if file doesnot exists directly using default photo
                     $this->photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_GROUP_PHOTO);
                     $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_GROUP_PHOTO)));
                 }
             } else {
                 $this->photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_GROUP_PHOTO);
                 $this->thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_GROUP_PHOTO)));
             }
             if (isset($array['LocationText'])) {
                 $this->location = $array['LocationText'];
             } else {
                 $this->location = "";
             }
             if (isset($array['LocationCountry'])) {
                 $cs = getCountryList();
                 $this->countrycode = $array['LocationCountry'];
                 if (isset($cs[$array['LocationCountry']])) {
                     $this->country = $cs[$array['LocationCountry']];
                 }
             } else {
                 $this->countrycode = "";
                 $this->country = "";
             }
             if (isset($array['LocationLat'])) {
                 $this->locationlat = $array['LocationLat'];
             }
             if (isset($array['LocationLng'])) {
                 $this->locationlng = $array['LocationLng'];
             }
         }
     } else {
         return database_error();
     }
     $this->loadmembers();
     $this->loadpendingmembers();
     $this->getDebateCount();
     $this->getVoteCount();
     return $this;
 }
 $array = $registeredUsers[$i];
 $name = $array['Name'];
 $userid = $array['UserID'];
 $date = $array['CreationDate'];
 $desc = $array['Description'];
 $website = $array['Website'];
 $lastlogin = $array['LastLogin'];
 $photo = '';
 $thumb = '';
 if ($array['Photo']) {
     $originalphotopath = $HUB_FLM->createUploadsDirPath($userid . "/" . stripslashes($array['Photo']));
     if (file_exists($originalphotopath)) {
         $photo = $HUB_FLM->getUploadsWebPath($userid . "/" . stripslashes($array['Photo']));
         $thumb = $HUB_FLM->getUploadsWebPath($userid . "/" . str_replace('.', '_thumb.', stripslashes($array['Photo'])));
         if (!file_exists($thumb)) {
             create_image_thumb($array['Photo'], $CFG->IMAGE_THUMB_WIDTH, $userid);
         }
     } else {
         $photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_USER_PHOTO);
         $thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_USER_PHOTO)));
     }
 } else {
     $photo = $HUB_FLM->getUploadsWebPath($CFG->DEFAULT_USER_PHOTO);
     $thumb = $HUB_FLM->getUploadsWebPath(str_replace('.', '_thumb.', stripslashes($CFG->DEFAULT_USER_PHOTO)));
 }
 $location = "";
 $country = "";
 if (isset($array['LocationText'])) {
     $location = $array['LocationText'];
 }
 if (isset($array['LocationCountry'])) {
示例#6
0
/**
 * Upload an image and place in current user's uploads folder.
 * checking it's actually an image and get it resized to default comment image size
 * on success return file name;
 * of failure return empty string. Error message go into $error passed in.
 *
 * @param string $field
 * @param array $errors
 * @return filename or empty string
 */
function uploadImageToFitComments($field, &$errors, $directory = "", $maxwidth, $maxheight)
{
    global $CFG, $USER, $LNG, $HUB_FLM;
    if ($directory == "") {
        if (!isset($USER->userid)) {
            array_push($errors, $LNG->CORE_UNKNOWN_USER_ERROR);
            return "";
        } else {
            $directory = $USER->userid;
        }
    }
    if ($_FILES[$field]['tmp_name'] != "") {
        $target_path = $HUB_FLM->createUploadsDirPath($directory . "/");
        if (!file_exists($target_path)) {
            mkdir($target_path, 0777, true);
        }
        $t_filename = basename(preg_replace('/([^A-Za-z0-9.])/i', '', $_FILES[$field]['name']));
        //replace the filetype with png (as the resize image code makes everything a png)
        $filename = preg_replace('/(.[B|b][m|M][p|P]$)/i', '.png', $t_filename);
        $filename = preg_replace('/(.[G|g][i|I][f|F]$)/i', '.png', $t_filename);
        $filename = preg_replace('/(.[J|j][p|P][g|G]$)/i', '.png', $t_filename);
        $filename = preg_replace('/(.[J|j][p|P][e|E][g|G]$)/i', '.png', $t_filename);
        $target_path = $target_path . $filename;
        if (!getimagesize($_FILES[$field]['tmp_name'])) {
            array_push($errors, $LNG->CORE_NOT_IMAGE_ERROR);
            return "";
        } else {
            if (filesize($_FILES[$field]['tmp_name']) > $CFG->IMAGE_MAX_FILESIZE) {
                array_push($errors, $LNG->CORE_NOT_IMAGE_TOO_LARGE_ERROR);
                return "";
            } else {
                if (!move_uploaded_file($_FILES[$field]['tmp_name'], $target_path)) {
                    array_push($errors, $LNG->CORE_NOT_IMAGE_UPLOAD_ERROR);
                    return "";
                }
            }
        }
        $imageinfo = getimagesize($target_path);
        $width = $imageinfo[0];
        $height = $imageinfo[1];
        //resize image
        if (!resize_image($target_path, $target_path, $width)) {
            //delete the file, it could be dodgy
            unlink($target_path);
            array_push($errors, $LNG->CORE_NOT_IMAGE_RESIZE_ERROR);
            return "";
        }
        $size = calculateAspectRatioFit($width, $height, $maxwidth, $maxheight);
        if (!create_image_thumb($filename, $size['width'], $directory)) {
            //delete the file, it could be dodgy
            unlink($target_path);
            array_push($errors, $LNG->CORE_NOT_IMAGE_SCALE_ERROR);
            return "";
        }
        return $filename;
    }
    return "";
}
示例#7
0
/**
 * Upload an image and place in current user's uploads folder.
 * checking it's actually an image and get it resized to default image size
 * on success return file name;
 * of failure return empty string. Error message go inot $error passed in.
 *
 * @param string $field
 * @param array $errors
 * @return filename or empty string
 */
function uploadImageToFit($field, &$errors, $directory = "")
{
    global $CFG, $USER, $LNG, $HUB_FLM;
    if ($directory == "") {
        if (!isset($USER->userid)) {
            array_push($errors, $LNG->CORE_UNKNOWN_USER_ERROR);
            return "";
        } else {
            $directory = $USER->userid;
        }
    }
    if ($_FILES[$field]['tmp_name'] != "") {
        $target_path = $HUB_FLM->createUploadsDirPath($directory . "/");
        if (!file_exists($target_path)) {
            mkdir($target_path, 0777, true);
        }
        //$dt = time();
        //replace any non alphanum chars in filename
        //should warn user about the file type Gary 2009. 01. 13
        //$t_filename = $dt ."_". basename( preg_replace('/([^A-Za-z0-9.])/i', '',$_FILES[$field]['name']));
        $t_filename = basename(preg_replace('/([^A-Za-z0-9.])/i', '', $_FILES[$field]['name']));
        //echo "t-filename: " . $t_filename;
        //replace the filetype with png (as the resize image code makes everything a png)
        $filename = preg_replace('/(.[B|b][m|M][p|P]$)/i', '.png', $t_filename);
        $filename = preg_replace('/(.[G|g][i|I][f|F]$)/i', '.png', $t_filename);
        $filename = preg_replace('/(.[J|j][p|P][g|G]$)/i', '.png', $t_filename);
        $filename = preg_replace('/(.[J|j][p|P][e|E][g|G]$)/i', '.png', $t_filename);
        //echo "filename: ".$filename;
        //exit();
        $target_path = $target_path . $filename;
        if (!getimagesize($_FILES[$field]['tmp_name'])) {
            array_push($errors, $LNG->CORE_NOT_IMAGE_ERROR);
            return "";
        } else {
            if (filesize($_FILES[$field]['tmp_name']) > $CFG->IMAGE_MAX_FILESIZE) {
                array_push($errors, $LNG->CORE_NOT_IMAGE_TOO_LARGE_ERROR);
                return "";
            } else {
                if (!move_uploaded_file($_FILES[$field]['tmp_name'], $target_path)) {
                    array_push($errors, $LNG->CORE_NOT_IMAGE_UPLOAD_ERROR);
                    return "";
                }
            }
        }
        $imageinfo = getimagesize($target_path);
        $width = $imageinfo[0];
        $height = $imageinfo[1];
        //scale
        if ($width > $CFG->IMAGE_WIDTH || $height > $CFG->IMAGE_HEIGHT) {
            $new_width = floatval($CFG->IMAGE_WIDTH);
            $new_height = $height * ($new_width / $width);
            if ($new_height < $CFG->IMAGE_HEIGHT) {
                $new_height = floatval($CFG->IMAGE_HEIGHT);
                $new_width = $width * ($new_height / $height);
                if ($new_width >= $CFG->IMAGE_WIDTH) {
                    if (!resize_image($target_path, $target_path, $CFG->IMAGE_HEIGHT)) {
                        //delete the file, it could be dodgy
                        unlink($target_path);
                        array_push($errors, $LNG->CORE_NOT_IMAGE_RESIZE_ERROR);
                        return "";
                    }
                }
            } else {
                if (!resize_image($target_path, $target_path, $CFG->IMAGE_WIDTH)) {
                    //delete the file, it could be dodgy
                    unlink($target_path);
                    array_push($errors, $LNG->CORE_NOT_IMAGE_RESIZE_ERROR);
                    return "";
                }
            }
        }
        $imageinfo = getimagesize($target_path);
        $width = $imageinfo[0];
        $height = $imageinfo[1];
        //error_log($width);
        //error_log($height);
        if ($width < $CFG->IMAGE_WIDTH || $height < $CFG->IMAGE_HEIGHT) {
            if (!image_scale_up($target_path, $target_path, $CFG->IMAGE_WIDTH, $CFG->IMAGE_HEIGHT)) {
                //delete the file, it could be dodgy
                unlink($target_path);
                array_push($errors, $LNG->CORE_NOT_IMAGE_RESIZE_ERROR);
                return "";
            }
        } else {
            if ($width > $CFG->IMAGE_WIDTH || $height > $CFG->IMAGE_HEIGHT) {
                if (!crop_image($target_path, $target_path, 0, 0, $CFG->IMAGE_WIDTH, $CFG->IMAGE_HEIGHT)) {
                    //delete the file, it could be dodgy
                    unlink($target_path);
                    array_push($errors, $LNG->CORE_NOT_IMAGE_RESIZE_ERROR);
                    return "";
                }
            }
        }
        if (!create_image_thumb($filename, $CFG->IMAGE_THUMB_WIDTH, $directory)) {
            //delete the file, it could be dodgy
            unlink($target_path);
            array_push($errors, $LNG->CORE_NOT_IMAGE_SCALE_ERROR);
            return "";
        }
        return $filename;
    }
    return "";
}