|
@ -2,21 +2,16 @@ |
|
|
|
|
|
|
|
|
abstract class Upload |
|
|
abstract class Upload |
|
|
{ |
|
|
{ |
|
|
const PATH_WEB_ROOT = '/var/www/10ballov/face/htdocs'; |
|
|
|
|
|
|
|
|
|
|
|
protected static $dir_image_cache = '/media/cache/images'; |
|
|
|
|
|
|
|
|
|
|
|
protected static $dir_image_originals = '/media/original'; |
|
|
|
|
|
|
|
|
|
|
|
const SAVE_ORIGINAL_IMAGE = 1; |
|
|
|
|
|
|
|
|
protected static $dir_image_cache = 'media/cache/images'; |
|
|
|
|
|
|
|
|
public static function getGreagwarImage($file_path) |
|
|
public static function getGreagwarImage($file_path) |
|
|
{ |
|
|
{ |
|
|
require_once PATH . '/lib/GreagwarImage/GreagwarImage.php'; |
|
|
require_once PATH . '/lib/GreagwarImage/GreagwarImage.php'; |
|
|
$greagwar_image = new GreagwarImage($file_path); |
|
|
$greagwar_image = new GreagwarImage($file_path); |
|
|
$greagwar_image->setCacheDir(self::PATH_WEB_ROOT . self::$dir_image_cache); |
|
|
|
|
|
|
|
|
$greagwar_image->setCacheDir(Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . self::$dir_image_cache); |
|
|
return $greagwar_image; |
|
|
return $greagwar_image; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $class string |
|
|
* @param $class string |
|
|
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...']) |
|
|
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...']) |
|
@ -34,17 +29,6 @@ abstract class Upload |
|
|
$image->original_filename = $file['name']; |
|
|
$image->original_filename = $file['name']; |
|
|
|
|
|
|
|
|
$greagwar_image = self::getGreagwarImage($file['tmp_name']); |
|
|
$greagwar_image = self::getGreagwarImage($file['tmp_name']); |
|
|
if (self::SAVE_ORIGINAL_IMAGE) { |
|
|
|
|
|
$path_for_save_original = self::PATH_WEB_ROOT . self::$dir_image_originals . DIRECTORY_SEPARATOR . $class; |
|
|
|
|
|
if (!file_exists($path_for_save_original)) { |
|
|
|
|
|
mkdir($path_for_save_original); |
|
|
|
|
|
chmod($path_for_save_original, 0777); |
|
|
|
|
|
} |
|
|
|
|
|
$basename = $image->original_filename . '_' . md5(uniqid($image->original_filename, true)); |
|
|
|
|
|
$extension = mb_substr($image->original_filename, mb_strrpos($image->original_filename, '.') + 1); |
|
|
|
|
|
$extension = mb_strtolower($extension); |
|
|
|
|
|
copy($file['tmp_name'], $path_for_save_original . DIRECTORY_SEPARATOR . $basename . '.' . $extension); |
|
|
|
|
|
} |
|
|
|
|
|
self::saveImage($image, $greagwar_image); |
|
|
self::saveImage($image, $greagwar_image); |
|
|
if ($force_create_variants) { |
|
|
if ($force_create_variants) { |
|
|
$sizes = $image->getSizes(); |
|
|
$sizes = $image->getSizes(); |
|
@ -73,7 +57,7 @@ abstract class Upload |
|
|
$file_path = $greagwar_image->cacheFile($image->type, 87, true); |
|
|
$file_path = $greagwar_image->cacheFile($image->type, 87, true); |
|
|
$image->size = filesize($file_path); |
|
|
$image->size = filesize($file_path); |
|
|
$path_parts = pathinfo($file_path); |
|
|
$path_parts = pathinfo($file_path); |
|
|
$image->path = preg_replace('#^' . self::PATH_WEB_ROOT . '/#', '', $path_parts['dirname']); |
|
|
|
|
|
|
|
|
$image->path = preg_replace('#^' . Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']); |
|
|
$image->filename = $path_parts['basename']; |
|
|
$image->filename = $path_parts['basename']; |
|
|
$image->width = $greagwar_image->width(); |
|
|
$image->width = $greagwar_image->width(); |
|
|
$image->height = $greagwar_image->height(); |
|
|
$image->height = $greagwar_image->height(); |
|
|