13161 - fix logo/background thumbnail generation in admin category

This commit is contained in:
Rodney Figaro 2017-05-12 09:25:11 +02:00
parent 3163cc8461
commit b76115952b

View File

@ -229,46 +229,7 @@ class AdminCategoriesController extends AdminCategoriesControllerCore
return AdminController::renderForm();
}
/*
public function postProcess() {
parent::postProcess();
$images = array('banner' => 'banners');
foreach($images as $imageName => $folder)
{
if(isset($_FILES[$imageName]) && !empty($_FILES[$imageName]['tmp_name']))
{
$obj = $this->loadObject(TRUE);
$fileTemp = $_FILES[$imageName]['tmp_name'];
$fileParts = pathinfo($_FILES[$imageName]['name']);
if($fileParts['extension'] == 'jpg')
{
if(!is_dir(_PS_CAT_IMG_DIR_.$folder))
mkdir(_PS_CAT_IMG_DIR_.$folder, 0775);
$res = move_uploaded_file($fileTemp, _PS_CAT_IMG_DIR_.$folder.'/'.$obj->id.'.jpg');
if(!$res)
{
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), $obj->id.'.jpg');
}
else
{
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), $obj->id.'.jpg');
}
}
else
{
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), $obj->id.'.jpg');
}
}
}
}
*/
protected function postImage($id)
{
$images = array(
@ -276,10 +237,8 @@ class AdminCategoriesController extends AdminCategoriesControllerCore
'bkg' => 'bkg'
);
foreach($images as $imageName => $folder)
{
if(isset($_FILES[$imageName]) && !empty($_FILES[$imageName]['tmp_name']))
{
foreach($images as $imageName => $folder){
if(isset($_FILES[$imageName]) && !empty($_FILES[$imageName]['tmp_name'])){
$obj = $this->loadObject(TRUE);
@ -287,28 +246,22 @@ class AdminCategoriesController extends AdminCategoriesControllerCore
$fileParts = pathinfo($_FILES[$imageName]['name']);
$ext = strtolower($fileParts['extension']);
if ($ext == 'jpg' ||
$ext == 'jpeg' ||
$ext == 'png')
{
if(!is_dir(_PS_CAT_IMG_DIR_.$folder)){
if ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png') {
if(!is_dir(_PS_CAT_IMG_DIR_.$folder)) {
mkdir(_PS_CAT_IMG_DIR_.$folder, 0775);
}
$target_path = _PS_CAT_IMG_DIR_.$folder.'/'.$obj->id.'.'.($ext=='png'?'png':'jpg');
$res = move_uploaded_file($fileTemp, $target_path);
if(!$res)
{
if(!$res) {
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), $obj->id.'.'.$ext);
}
else
{
ImageManager::thumbnail($target_path, $obj->getThumbnailFilename($folder, $this->imageType), 350, $this->imageType, true, true);
else {
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), $obj->id.'.'.$ext);
}
}
else
{
else {
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), $obj->id.'.'.$ext);
}
}
@ -335,8 +288,7 @@ class AdminCategoriesController extends AdminCategoriesControllerCore
return $image;
}
$image['thumb'] = '<img src="../img/tmp/'.$obj->getThumbnailFilename($folder, $this->imageType).'?time='.time().'" alt="" class="imgm img-thumbnail" />';
$image['thumb'] = ImageManager::thumbnail($image['path'], $obj->getThumbnailFilename($folder, $this->imageType), 350, $this->imageType, true, true);
$image['size'] = filesize($image['path']);
return $image;
}