[*] BO : Removed size limit for image upload (BL006, CC136)

This commit is contained in:
tDidierjean
2011-09-12 09:14:07 +00:00
parent beea76b0bd
commit 7cd878079c
17 changed files with 43 additions and 51 deletions
-2
View File
@@ -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;
-2
View File
@@ -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';
-2
View File
@@ -27,8 +27,6 @@
class AdminCategories extends AdminTab
{
protected $maxImageSize = 300000;
/** @var object Category() instance for navigation*/
private $_category;
+1 -1
View File
@@ -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
{
-2
View File
@@ -27,8 +27,6 @@
class AdminManufacturers extends AdminTab
{
protected $maxImageSize = 200000;
/** @var array countries list */
private $countriesArray = array();
+3 -10
View File
@@ -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
<td style="padding-bottom:5px;">
<input type="file" id="image_product" name="image_product" />
<p>
'.$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.').'
<br />'.$this->l('You can also upload a ZIP file containing several images. Thumbnails will be resized automatically.').'
</p>
</td>
+2 -4
View File
@@ -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
<div class="margin-form">
<input type="hidden" id="stay_here" name="stay_here" value="" />
<input type="file" name="image" id="image_input" /> <input type="button" value="'.$this->l('Upload image').'" onclick="{$(\'#stay_here\').val(\'true\');$(\'#scenesForm\').submit();}" class="button" /><br/>
<p>'.$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.').'.<br />'.$this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'</p>';
<p>'.$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.').'.<br />'.$this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'</p>';
if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.$obj->id.'-large_scene.jpg'))
{
@@ -218,7 +216,7 @@ class AdminScenes extends AdminTab
echo '<label>'.$this->l('Alternative thumbnail:').' </label>
<div class="margin-form">
<input type="file" name="thumb" id="thumb_input" />&nbsp;&nbsp;'.$this->l('(optional)').'
<p>'.$this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.').'<br />'.$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)').'.<br />'.$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'</p>
<p>'.$this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.').'<br />'.$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)').'.<br />'.$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'</p>
';
if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.'thumbs/'.$obj->id.'-thumb_scene.jpg'))
echo '<img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="'._THEME_SCENE_DIR_.'thumbs/'.$obj->id.'-thumb_scene.jpg" /><br />';
-2
View File
@@ -27,8 +27,6 @@
class AdminSuppliers extends AdminTab
{
protected $maxImageSize = 200000;
public function __construct()
{
$this->table = 'supplier';
+8 -4
View File
@@ -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 */
+17
View File
@@ -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;
}
}
/**
+6 -6
View File
@@ -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');
+2 -5
View File
@@ -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 */
@@ -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;
+1 -4
View File
@@ -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;
-1
View File
@@ -34,7 +34,6 @@ class HomeSlide extends ObjectModel
public $image;
public $active;
public $position;
public $maxImageSize = 307200;
protected $fieldsValidate = array(
'active' => 'isunsignedInt',
+1 -1
View File
@@ -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;
+1 -2
View File
@@ -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'))