[-] BO : #PSCFV-2716 : Fix memory limit when upload image file
This commit is contained in:
+29
-10
@@ -51,16 +51,9 @@ class ImageManagerCore
|
||||
{
|
||||
$infos = getimagesize($image);
|
||||
|
||||
$memory_limit = Tools::getMemoryLimit();
|
||||
// memory_limit == -1 => unlimited memory
|
||||
if (function_exists('memory_get_usage') && (int)$memory_limit != -1)
|
||||
{
|
||||
$current_memory = memory_get_usage();
|
||||
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (($infos[0] * $infos[1] * $infos['bits'] * (isset($infos['channels']) ? ($infos['channels'] / 8) : 1) + pow(2, 16)) * 1.8 + $current_memory > $memory_limit - 1024 * 1024)
|
||||
return false;
|
||||
}
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (!ImageManager::checkImageMemoryLimit($image))
|
||||
return false;
|
||||
|
||||
$x = $infos[0];
|
||||
$y = $infos[1];
|
||||
@@ -85,6 +78,32 @@ class ImageManagerCore
|
||||
return '<img src="'._PS_TMP_IMG_.$cache_image.(!$disable_cache ? '?time='.time() : '').'" alt="" class="imgm" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if memory limit is too long or not
|
||||
*
|
||||
* @static
|
||||
* @param $image
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkImageMemoryLimit($image)
|
||||
{
|
||||
$infos = getimagesize($image);
|
||||
|
||||
$memory_limit = Tools::getMemoryLimit();
|
||||
// memory_limit == -1 => unlimited memory
|
||||
if (function_exists('memory_get_usage') && (int)$memory_limit != -1)
|
||||
{
|
||||
$current_memory = memory_get_usage();
|
||||
$channel = isset($infos['channels']) ? ($infos['channels'] / 8) : 1;
|
||||
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (($infos[0] * $infos[1] * $infos['bits'] * $channel + pow(2, 16)) * 1.8 + $current_memory > $memory_limit - 1024 * 1024)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize, cut and optimize image
|
||||
*
|
||||
|
||||
@@ -2463,9 +2463,14 @@ class AdminControllerCore extends Controller
|
||||
if (!move_uploaded_file($_FILES[$name]['tmp_name'], $tmp_name))
|
||||
return false;
|
||||
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (!ImageManager::checkImageMemoryLimit($tmp_name))
|
||||
$this->errors[] = Tools::displayError('This image cannot be loaded due to memory limit restrictions, please increase your memory_limit value on your server configuration.');
|
||||
|
||||
// Copy new image
|
||||
if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_.$dir.$id.'.'.$this->imageType, (int)$width, (int)$height, ($ext ? $ext : $this->imageType)))
|
||||
if (empty($this->errors) && !ImageManager::resize($tmp_name, _PS_IMG_DIR_.$dir.$id.'.'.$this->imageType, (int)$width, (int)$height, ($ext ? $ext : $this->imageType)))
|
||||
$this->errors[] = Tools::displayError('An error occurred while uploading image.');
|
||||
|
||||
if (count($this->errors))
|
||||
return false;
|
||||
if ($this->afterImageUpload())
|
||||
|
||||
@@ -790,6 +790,11 @@ class AdminImportControllerCore extends AdminController
|
||||
break;
|
||||
}
|
||||
$url = str_replace(' ', '%20', trim($url));
|
||||
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (!ImageManager::checkImageMemoryLimit($url))
|
||||
return false;
|
||||
|
||||
// 'file_exists' doesn't work on distant file, and getimagesize make the import slower.
|
||||
// Just hide the warning, the traitment will be the same.
|
||||
if (@copy($url, $tmpfile))
|
||||
|
||||
@@ -93,6 +93,7 @@ $_ERRORS['200cb26c2479e770241b1c62ccfb8e08'] = 'Une erreur est survenue lors de
|
||||
$_ERRORS['204c3558e41366f3d558ce8e01426a22'] = 'Le champ %s est requis.';
|
||||
$_ERRORS['20c6125376d8de28149d655c7cc25e32'] = 'Aucun fichier n\'a été envoyé';
|
||||
$_ERRORS['20eb7f9857d85d1d0c8a1e0ddf8545b8'] = 'La class Tax Manager n\'a pas été trouver [%s]';
|
||||
$_ERRORS['21e09791b722e841d87e2db8099d87f7'] = 'Cette image ne peut pas être chargé en raison de restrictions limites de la mémoire. S\'il vous plaît veuillez augmenter la valeur memory_limit dans fichier de configuration de votre serveur.';
|
||||
$_ERRORS['221cbaf37b5e5d712e9d100c75e7477a'] = 'La valeur de la remise n\'est pas valable';
|
||||
$_ERRORS['232c743d230be418c2b444f3c750300e'] = 'Vous devez ajouter une quantité minimum de %d';
|
||||
$_ERRORS['2366efc5c5a14abdb1b6da3322b39460'] = 'Votre compte invité a déjà été transformé en un compte client.';
|
||||
@@ -366,6 +367,7 @@ $_ERRORS['8e4b5b9003a1e89146ecd623f76f4179'] = 'Veuillez définir une profondeur
|
||||
$_ERRORS['8eccd648c123a09bcf8520fea052861d'] = 'Une erreur est survenue lors de la suppression du produit.';
|
||||
$_ERRORS['8ecf4968ba36c1f1424e96a01aa9f4f0'] = 'Une erreur est survenue pendant l\'installation du module :';
|
||||
$_ERRORS['8f3d9ee281e1abb9111486bcbda6804e'] = 'Erreur : certaines ou toutes les images n\'ont pu être déplacées.';
|
||||
$_ERRORS['8f62a26bf441ad698c2c562ec10448c4'] = 'Tous les modules ne peuvent pas être chargé en raison de restrictions limites de la mémoire. S\'il vous plaît veuillez augmenter la valeur memory_limit dans fichier de configuration de votre serveur.';
|
||||
$_ERRORS['8fd6c902e0a6186ebc62b4c3c65dc528'] = 'Vous ne pouvez pas supprimer ce compte puisqu\'il gère des entrepôts. Veuillez d\'abord vérifier vos entrepôts.';
|
||||
$_ERRORS['902b0d55fddef6f8d651fe1035b7d4bd'] = 'Erreur';
|
||||
$_ERRORS['9072e6a7f1693ef1fb211f2f6dc56d02'] = 'Prix requis pour l\'attribut';
|
||||
|
||||
Reference in New Issue
Block a user