private function gicon_upload_file() { $fileElementName = 'wpl_gicon_file'; $file = wpl_request::getVar($fileElementName, '', 'FILES'); $ext_array = array('jpg', 'png', 'gif', 'jpeg'); $error = ""; $msg = ""; if (!empty($file['error']) or (empty($file['tmp_name']) or $file['tmp_name'] == 'none')) { $error = __("An error occurred uploading your file!", WPL_TEXTDOMAIN); } else { $extention = strtolower(wpl_file::getExt($file['name'])); $name = strtolower(wpl_file::stripExt(wpl_file::getName($file['name']))); if (!in_array($extention, $ext_array)) { $error = __("File extension should be jpg, png or gif", WPL_TEXTDOMAIN); } /** check the file size **/ $filesize = @filesize($file['tmp_name']); if ($filesize > 500 * 1024) { $error .= __("Icons should not be bigger than 500KB!", WPL_TEXTDOMAIN); @unlink($file); } if ($error == "") { $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'listing_types' . DS . 'gicon' . DS . $name . '.' . $extention; while (wpl_file::exists($dest)) { $name .= '_copy'; $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'listing_types' . DS . 'gicon' . DS . $name . '.' . $extention; } wpl_file::upload($file['tmp_name'], $dest); } } $message = ''; $response = array('error' => $error, 'message' => $message); echo json_encode($response); exit; }
/** * Creates profile image * @author Howard <*****@*****.**> * @param string $source * @param int $width * @param int $height * @param array $params * @param int $watermark * @param int $rewrite * @param int $crop * description: resize and watermark images specially */ public static function create_profile_images($source, $width, $height, $params, $watermark = 0, $rewrite = 0, $crop = '') { /** first validation **/ if (!trim($source)) { return NULL; } $image_name = wpl_file::stripExt($params['image_name']); $image_ext = wpl_file::getExt($params['image_name']); $resized_image_name = 'th' . $image_name . '_' . $width . 'x' . $height . '.' . $image_ext; $image_dest = wpl_items::get_path($params['image_parentid'], 2) . $resized_image_name; $image_url = wpl_items::get_folder($params['image_parentid'], 2) . $resized_image_name; /** check resized files existance and rewrite option **/ if ($rewrite or !wpl_file::exists($image_dest)) { if ($watermark) { self::resize_watermark_image($source, $image_dest, $width, $height); } else { self::resize_image($source, $image_dest, $width, $height, $crop); } } return $image_url; }