public static function uploadUserAvatar($avatar, $user_id = 0) { try { $added_date = time(); $username = md5($user_id); $user_info = new Model_Users_User($user_id); if ($user_info->count()) { $added_date = $user_info['date_added']; $username = $user_info['username']; } if (($imageinfo = @getimagesize($avatar)) !== false) { $ext = JO_File_Ext::getExtFromMime($imageinfo['mime']); $name = $username . '_' . $user_id . '.' . $ext; $image_path = '/users/' . WM_Date::format($added_date, 'yy/mm/'); //$name = self::rename_if_exists($image_path, $name); if (!file_exists(BASE_PATH . '/uploads' . $image_path) || !is_dir(BASE_PATH . '/uploads' . $image_path)) { mkdir(BASE_PATH . '/uploads' . $image_path, 0777, true); } if (copy($avatar, BASE_PATH . '/uploads' . $image_path . $name)) { if (file_exists(BASE_PATH . '/uploads' . $image_path . $name)) { return array('store' => 'Model_Upload_Locale', 'image' => $image_path . $name, 'width' => 0, 'height' => 0); } else { return false; } } else { return false; } } else { return false; } } catch (JO_Exception $e) { self::$error = $e->getMessage(); return false; } return false; }
public static function uploadEventImage($avatar, $user_id = 0) { try { $added_date = time(); if (is_array($user_info = Model_Users::getUser($user_id))) { $added_date = $user_info['date_added']; } $date_added = WM_Date::format($added_date, 'yy-mm-dd H:i:s'); if (($imageinfo = @getimagesize($avatar)) !== false) { $ext = JO_File_Ext::getExtFromMime($imageinfo['mime']); $ext = '.' . $ext; $name = $user_id . $ext; $image_path = '/users/' . WM_Date::format($added_date, 'yy/mm/'); //$name = self::rename_if_exists($image_path, $name); if (!file_exists(BASE_PATH . '/uploads' . $image_path) || !is_dir(BASE_PATH . '/uploads' . $image_path)) { @mkdir(BASE_PATH . '/uploads' . $image_path, 0777, true); } if (@copy($avatar, BASE_PATH . '/uploads' . $image_path . $name)) { if (file_exists(BASE_PATH . '/uploads' . $image_path . $name)) { return array('store' => 'locale', 'image' => $image_path . $name, 'width' => 0, 'height' => 0); } else { return false; } } else { return false; } } else { return false; } } catch (JO_Exception $e) { return false; } return false; }