public function uploadUserImage($file, $image_ext, $image_name, $destinationpath, $user_id = 0) { $config_path = Config::get('generalConfig.user_image_folder'); $this->chkAndCreateFolder($config_path); $logged_user_id = $user_id; if (!$logged_user_id && isset(getAuthUser()->id)) { $logged_user_id = getAuthUser()->id; } // open file a image resource Image::make($file->getRealPath())->save(Config::get("generalConfig.user_image_folder") . $image_name . '_O.' . $image_ext); list($width, $height) = getimagesize($file); list($upload_img['width'], $upload_img['height']) = getimagesize(base_path() . '/public/' . $config_path . $image_name . '_O.' . $image_ext); $large_width = Config::get('generalConfig.user_image_large_width'); $large_height = Config::get('generalConfig.user_image_large_height'); if (isset($large_width) && isset($large_height)) { $img_size = CUtil::DISP_IMAGE($large_width, $large_height, $upload_img['width'], $upload_img['height'], true); Image::make($file->getRealPath())->resize($large_width, $large_height, true, false)->save($config_path . $image_name . '_L.' . $image_ext); } $small_width = Config::get("generalConfig.user_image_small_width"); $small_height = Config::get("generalConfig.user_image_small_height"); if (isset($small_width) && isset($small_height)) { $simg_size = CUtil::DISP_IMAGE($small_width, $small_height, $upload_img['width'], $upload_img['height'], true); Image::make($file->getRealPath())->resize($small_width, $small_height, true, false)->save($config_path . $image_name . '_S.' . $image_ext); } $thumb_width = Config::get("generalConfig.user_image_thumb_width"); $thumb_height = Config::get("generalConfig.user_image_thumb_height"); if (isset($thumb_width) && isset($thumb_height)) { $timg_size = CUtil::DISP_IMAGE($thumb_width, $thumb_height, $upload_img['width'], $upload_img['height'], true); Image::make($file->getRealPath())->resize($thumb_width, $thumb_height, true, false)->save($config_path . $image_name . '_T.' . $image_ext); } $img_path = Request::root() . '/' . $config_path; list($upload_input['small_width'], $upload_input['small_height']) = getimagesize($img_path . $image_name . '_S.' . $image_ext); list($upload_input['thumb_width'], $upload_input['thumb_height']) = getimagesize($img_path . $image_name . '_T.' . $image_ext); list($upload_input['large_width'], $upload_input['large_height']) = getimagesize($img_path . $image_name . '_L.' . $image_ext); $user_image = new UserImage(); $user_data = array('image_ext' => $image_ext, 'image_name' => $image_name, 'image_server_url' => $destinationpath, 'large_height' => $upload_input['large_height'], 'large_width' => $upload_input['large_width'], 'small_width' => $upload_input['small_width'], 'small_height' => $upload_input['small_height'], 'thumb_width' => $upload_input['thumb_width'], 'thumb_height' => $upload_input['thumb_height']); $user_image_details = UserImage::where('user_id', $logged_user_id)->first(); if (count($user_image_details) > 0) { $this->deleteImageFiles($user_image_details->image_name, $user_image_details->image_ext, $config_path); UserImage::where('user_id', $logged_user_id)->update($user_data); $id = $user_image_details->image_id; } else { $user_data['date_added'] = new DateTime(); $user_data['user_id'] = $logged_user_id; $id = $user_image->insertGetId($user_data); } return $id; }