diff --git a/admin-dev/tabs/AdminCMSCategories.php b/admin-dev/tabs/AdminCMSCategories.php index d19574b55..1d6aa57d6 100644 --- a/admin-dev/tabs/AdminCMSCategories.php +++ b/admin-dev/tabs/AdminCMSCategories.php @@ -29,8 +29,6 @@ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminCMSCategories extends AdminTab { - protected $maxImageSize = 300000; - /** @var object CMSCategory() instance for navigation*/ private $_CMSCategory; diff --git a/admin-dev/tabs/AdminCarriers.php b/admin-dev/tabs/AdminCarriers.php index c989bec7f..76bbd0745 100644 --- a/admin-dev/tabs/AdminCarriers.php +++ b/admin-dev/tabs/AdminCarriers.php @@ -29,8 +29,6 @@ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminCarriers extends AdminTab { - protected $maxImageSize = 30000; - public function __construct() { $this->table = 'carrier'; diff --git a/admin-dev/tabs/AdminCategories.php b/admin-dev/tabs/AdminCategories.php index 3ace735f2..69b19409d 100644 --- a/admin-dev/tabs/AdminCategories.php +++ b/admin-dev/tabs/AdminCategories.php @@ -27,8 +27,6 @@ class AdminCategories extends AdminTab { - protected $maxImageSize = 300000; - /** @var object Category() instance for navigation*/ private $_category; diff --git a/admin-dev/tabs/AdminLanguages.php b/admin-dev/tabs/AdminLanguages.php index 8abe35e0e..802704dde 100644 --- a/admin-dev/tabs/AdminLanguages.php +++ b/admin-dev/tabs/AdminLanguages.php @@ -66,7 +66,7 @@ class AdminLanguages extends AdminTab public function copyNoPictureImage($language) { if (isset($_FILES['no-picture']) and $_FILES['no-picture']['error'] === 0) - if ($error = checkImage($_FILES['no-picture'], $this->maxImageSize)) + if ($error = checkImage($_FILES['no-picture'], Tools::getMaxUploadSize())) $this->_errors[] = $error; else { diff --git a/admin-dev/tabs/AdminManufacturers.php b/admin-dev/tabs/AdminManufacturers.php index 1935e4a91..5c899ca8e 100644 --- a/admin-dev/tabs/AdminManufacturers.php +++ b/admin-dev/tabs/AdminManufacturers.php @@ -27,8 +27,6 @@ class AdminManufacturers extends AdminTab { - protected $maxImageSize = 200000; - /** @var array countries list */ private $countriesArray = array(); diff --git a/admin-dev/tabs/AdminProducts.php b/admin-dev/tabs/AdminProducts.php index 2c9c6cdbc..9959991c3 100644 --- a/admin-dev/tabs/AdminProducts.php +++ b/admin-dev/tabs/AdminProducts.php @@ -28,8 +28,7 @@ include_once(PS_ADMIN_DIR.'/tabs/AdminProfiles.php'); class AdminProducts extends AdminTab { - protected $maxImageSize = 2000000; - protected $maxFileSize = 10000000; + protected $maxFileSize = 20000000; private $_category; @@ -1009,12 +1008,6 @@ class AdminProducts extends AdminTab if (!$image->add()) throw new Exception(Tools::displayError('Error while creating additional image')); - if (filesize($subdir.$file) > $this->maxImageSize) - { - $image->delete(); - throw new Exception(Tools::displayError('Image is too large').' ('.(filesize($subdir.$file) / 1000).Tools::displayError('kB').'). '.Tools::displayError('Maximum allowed:').' '.($this->maxImageSize / 1000).Tools::displayError('kB')); - } - $ext = substr($file, -4); $type = (isset($types[$ext]) ? $types[$ext] : ''); if (!isPicture(array('tmp_name' => $subdir.$file, 'type' => $type))) @@ -1063,7 +1056,7 @@ class AdminProducts extends AdminTab { if (!isset($_FILES['image_product']['tmp_name'])) return false; - if ($error = checkImage($_FILES['image_product'], $this->maxImageSize)) + if ($error = checkImage($_FILES['image_product'])) $this->_errors[] = $error; else { @@ -2991,7 +2984,7 @@ class AdminProducts extends AdminTab

- '.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.($this->maxImageSize / 1000).''.$this->l('Kb max.').' + '.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.(Tools::getMaxUploadSize() / 1024).''.$this->l('Kb max.').'
'.$this->l('You can also upload a ZIP file containing several images. Thumbnails will be resized automatically.').'

diff --git a/admin-dev/tabs/AdminScenes.php b/admin-dev/tabs/AdminScenes.php index 9d7bd28b8..ddb043d6e 100644 --- a/admin-dev/tabs/AdminScenes.php +++ b/admin-dev/tabs/AdminScenes.php @@ -27,8 +27,6 @@ class AdminScenes extends AdminTab { - protected $maxImageSize = 1000000; - public function __construct() { $this->table = 'scene'; @@ -192,7 +190,7 @@ class AdminScenes extends AdminTab

-

'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('File size:').' '.($this->maxImageSize / 1000).''.$this->l('KB max.').' '.$this->l('If larger than the image size setting, the image will be reduced to ').' '.$largeSceneImageType['width'].'x'.$largeSceneImageType['height'].'px '.$this->l('(width x height). If smaller than the image-size setting, a white background will be added in order to achieve the correct image size.').'.
'.$this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

'; +

'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('File size:').' '.(Tools::getMaxUploadSize() / 1024).''.$this->l('KB max.').' '.$this->l('If larger than the image size setting, the image will be reduced to ').' '.$largeSceneImageType['width'].'x'.$largeSceneImageType['height'].'px '.$this->l('(width x height). If smaller than the image-size setting, a white background will be added in order to achieve the correct image size.').'.
'.$this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

'; if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.$obj->id.'-large_scene.jpg')) { @@ -218,7 +216,7 @@ class AdminScenes extends AdminTab echo '
  '.$this->l('(optional)').' -

'.$this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.').'
'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.($this->maxImageSize / 1000).''.$this->l('Kb max.').' '.$this->l('Automatically resized to').' '.$thumbSceneImageType['width'].'x'.$thumbSceneImageType['height'].'px '.$this->l('(width x height)').'.
'.$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

+

'.$this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.').'
'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.(Tools::getMaxUploadSize() / 1024).''.$this->l('Kb max.').' '.$this->l('Automatically resized to').' '.$thumbSceneImageType['width'].'x'.$thumbSceneImageType['height'].'px '.$this->l('(width x height)').'.
'.$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

'; if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.'thumbs/'.$obj->id.'-thumb_scene.jpg')) echo '
'; diff --git a/admin-dev/tabs/AdminSuppliers.php b/admin-dev/tabs/AdminSuppliers.php index ff60aa6f4..6fe626b41 100644 --- a/admin-dev/tabs/AdminSuppliers.php +++ b/admin-dev/tabs/AdminSuppliers.php @@ -27,8 +27,6 @@ class AdminSuppliers extends AdminTab { - protected $maxImageSize = 200000; - public function __construct() { $this->table = 'supplier'; diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 25d4ee943..17927169c 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -125,8 +125,10 @@ abstract class AdminTabCore /** @var string Order way (ASC, DESC) determined by arrows in list header */ protected $_orderWay; - /** @var integer Max image size for upload */ - protected $maxImageSize = 2000000; + /** @var integer Max image size for upload + * As of 1.5 it is recommended to not set a limit to max image size + **/ + protected $maxImageSize; /** @var array Errors displayed after post processing */ public $_errors = array(); @@ -1042,8 +1044,10 @@ abstract class AdminTabCore else return false; + // Check image validity - if ($error = checkImage($_FILES[$name], $this->maxImageSize)) + $max_size = isset($this->maxImageSize) ? $this->maxImageSize : 0; + if ($error = checkImage($_FILES[$name], Tools::getMaxUploadSize($max_size))) $this->_errors[] = $error; elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES[$name]['tmp_name'], $tmpName)) return false; @@ -1074,7 +1078,7 @@ abstract class AdminTabCore if (isset($_FILES[$name]['tmp_name']) AND !empty($_FILES[$name]['tmp_name'])) { /* Check ico validity */ - if ($error = checkIco($_FILES[$name], $this->maxImageSize)) + if ($error = checkIco($_FILES[$name])) $this->_errors[] = $error; /* Copy new ico */ diff --git a/classes/Tools.php b/classes/Tools.php index 595f6494a..0ca7f0e0a 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -2120,6 +2120,23 @@ FileETag INode MTime Size return $req; } + + /** + * Get max file upload size considering server settings and optional max value + * + * @param int $max_size optional max file size + * @return int max file size in bytes + */ + public static function getMaxUploadSize($max_size = 0) + { + $post_max_size = self::convertBytes(ini_get('post_max_size')); + $upload_max_filesize = self::convertBytes(ini_get('upload_max_filesize')); + if ($max_size > 0) + $result = min($post_max_size, $upload_max_filesize, $max_size); + else + $result = min($post_max_size, $upload_max_filesize); + return $result; + } } /** diff --git a/images.inc.php b/images.inc.php index c7f35cb49..6af0eada7 100644 --- a/images.inc.php +++ b/images.inc.php @@ -83,11 +83,11 @@ function cacheImage($image, $cacheImage, $size, $imageType = 'jpg', $disableCach * Check image upload * * @param array $file Upload $_FILE value - * @param integer $maxFileSize Maximum upload size + * @param integer $maxFileSize Maximum upload size (optional) */ -function checkImage($file, $maxFileSize) +function checkImage($file, $maxFileSize = 0) { - if ($file['size'] > $maxFileSize) + if ((int)$maxFileSize > 0 && $file['size'] > (int)$maxFileSize) return Tools::displayError('Image is too large').' ('.($file['size'] / 1000).Tools::displayError('KB').'). '.Tools::displayError('Maximum allowed:').' '.($maxFileSize / 1000).Tools::displayError('KB'); if (!isPicture($file)) return Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png'); @@ -169,11 +169,11 @@ function isPicture($file, $types = NULL) * Check icon upload * * @param array $file Upload $_FILE value - * @param integer $maxFileSize Maximum upload size + * @param integer $maxFileSize Maximum upload size (optional) */ -function checkIco($file, $maxFileSize) +function checkIco($file, $maxFileSize = 0) { - if ($file['size'] > $maxFileSize) + if ((int)$maxFileSize > 0 && $file['size'] > $maxFileSize) return Tools::displayError('Image is too large').' ('.($file['size'] / 1000).'ko). '.Tools::displayError('Maximum allowed:').' '.($maxFileSize / 1000).'ko'; if (substr($file['name'], -4) != '.ico') return Tools::displayError('Image format not recognized, allowed formats are: .ico'); diff --git a/modules/autoupgrade/AdminSelfTab.php b/modules/autoupgrade/AdminSelfTab.php index 3dde2d3df..59dc2ba50 100644 --- a/modules/autoupgrade/AdminSelfTab.php +++ b/modules/autoupgrade/AdminSelfTab.php @@ -117,9 +117,6 @@ abstract class AdminSelfTab /** @var string Order way (ASC, DESC) determined by arrows in list header */ protected $_orderWay; - /** @var integer Max image size for upload */ - protected $maxImageSize = 2000000; - /** @var array Errors displayed after post processing */ public $_errors = array(); @@ -1140,7 +1137,7 @@ abstract class AdminSelfTab return false; // Check image validity - if ($error = checkImage($_FILES[$name], $this->maxImageSize)) + if ($error = checkImage($_FILES[$name])) $this->_errors[] = $error; elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES[$name]['tmp_name'], $tmpName)) return false; @@ -1171,7 +1168,7 @@ abstract class AdminSelfTab if (isset($_FILES[$name]['tmp_name']) AND !empty($_FILES[$name]['tmp_name'])) { /* Check ico validity */ - if ($error = checkIco($_FILES[$name], $this->maxImageSize)) + if ($error = checkIco($_FILES[$name])) $this->_errors[] = $error; /* Copy new ico */ diff --git a/modules/blockreinsurance/blockreinsurance.php b/modules/blockreinsurance/blockreinsurance.php index 9b7257a3c..3839feb98 100644 --- a/modules/blockreinsurance/blockreinsurance.php +++ b/modules/blockreinsurance/blockreinsurance.php @@ -75,8 +75,6 @@ class blockreinsurance extends Module public function addToDB() { - $maxImageSize = 3007200; - if(isset($_POST['nbblocks'])) { for($i = 1; $i <= (int)$_POST['nbblocks']; $i++) @@ -84,7 +82,7 @@ class blockreinsurance extends Module $filename = explode('.', $_FILES['info'.$i.'_file']['name']); if (isset($_FILES['info'.$i.'_file']) AND isset($_FILES['info'.$i.'_file']['tmp_name']) AND !empty($_FILES['info'.$i.'_file']['tmp_name'])) { - if ($error = checkImage($_FILES['info'.$i.'_file'], $maxImageSize)) + if ($error = checkImage($_FILES['info'.$i.'_file'])) return false; elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['info'.$i.'_file']['tmp_name'], $tmpName)) return false; diff --git a/modules/editorial/editorial.php b/modules/editorial/editorial.php index 9fc562876..8437048cc 100644 --- a/modules/editorial/editorial.php +++ b/modules/editorial/editorial.php @@ -30,9 +30,6 @@ if (!defined('_PS_VERSION_')) class Editorial extends Module { - /** @var max image size */ - protected $maxImageSize = 307200; - public function __construct() { $this->name = 'editorial'; @@ -152,7 +149,7 @@ class Editorial extends Module Configuration::set('PS_IMAGE_GENERATION_METHOD', 1); if(file_exists(dirname(__FILE__).'/homepage_logo.jpg')) unlink(dirname(__FILE__).'/homepage_logo.jpg'); - if ($error = checkImage($_FILES['body_homepage_logo'], $this->maxImageSize)) + if ($error = checkImage($_FILES['body_homepage_logo'])) $errors .= $error; elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['body_homepage_logo']['tmp_name'], $tmpName)) return false; diff --git a/modules/homeslider/HomeSlide.php b/modules/homeslider/HomeSlide.php index 1975ebbaf..07042f403 100644 --- a/modules/homeslider/HomeSlide.php +++ b/modules/homeslider/HomeSlide.php @@ -34,7 +34,6 @@ class HomeSlide extends ObjectModel public $image; public $active; public $position; - public $maxImageSize = 307200; protected $fieldsValidate = array( 'active' => 'isunsignedInt', diff --git a/modules/homeslider/homeslider.php b/modules/homeslider/homeslider.php index 5dfc113d0..a446a6942 100644 --- a/modules/homeslider/homeslider.php +++ b/modules/homeslider/homeslider.php @@ -503,7 +503,7 @@ class HomeSlider extends Module /* Uploads image and sets slide */ if (isset($_FILES['image_'.$language['id_lang']]) AND isset($_FILES['image_'.$language['id_lang']]['tmp_name']) AND !empty($_FILES['image_'.$language['id_lang']]['tmp_name'])) { - if ($error = checkImage($_FILES['image_'.$language['id_lang']], $slide->maxImageSize)) + if ($error = checkImage($_FILES['image_'.$language['id_lang']])) $errors .= $error; elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['image_'.$language['id_lang']]['tmp_name'], $tmpName)) return false; diff --git a/modules/watermark/watermark.php b/modules/watermark/watermark.php index b7885841f..5be952a0c 100644 --- a/modules/watermark/watermark.php +++ b/modules/watermark/watermark.php @@ -39,7 +39,6 @@ class Watermark extends Module private $transparency; private $imageTypes = array(); private $watermarkTypes; - private $maxImageSize = 100000; public function __construct() { @@ -132,7 +131,7 @@ class Watermark extends Module if (isset($_FILES['PS_WATERMARK']) AND !empty($_FILES['PS_WATERMARK']['tmp_name'])) { /* Check watermark validity */ - if ($error = checkImage($_FILES['PS_WATERMARK'], $this->maxImageSize)) + if ($error = checkImage($_FILES['PS_WATERMARK'])) $this->_errors[] = $error; /* Copy new watermark */ elseif(!copy($_FILES['PS_WATERMARK']['tmp_name'], dirname(__FILE__).'/watermark.gif'))