/** * @deprecated 1.5.0 */ function isPicture($file, $types = null) { Tools::displayAsDeprecated(); return ImageManager::isRealImage($file['tmp_name'], $file['type'], $types); }
public function ajaxProcessUploadLogo() { if (!$this->access('edit')) { die('<return result="error" message="' . $this->trans('You do not have permission to use this wizard.', array(), 'Admin.Shipping.Notification') . '" />'); } $allowedExtensions = array('jpeg', 'gif', 'png', 'jpg'); $logo = isset($_FILES['carrier_logo_input']) ? $_FILES['carrier_logo_input'] : false; if ($logo && !empty($logo['tmp_name']) && $logo['tmp_name'] != 'none' && (!isset($logo['error']) || !$logo['error']) && preg_match('/\\.(jpe?g|gif|png)$/', $logo['name']) && is_uploaded_file($logo['tmp_name']) && ImageManager::isRealImage($logo['tmp_name'], $logo['type'])) { $file = $logo['tmp_name']; do { $tmp_name = uniqid() . '.jpg'; } while (file_exists(_PS_TMP_IMG_DIR_ . $tmp_name)); if (!ImageManager::resize($file, _PS_TMP_IMG_DIR_ . $tmp_name)) { die('<return result="error" message="Impossible to resize the image into ' . Tools::safeOutput(_PS_TMP_IMG_DIR_) . '" />'); } @unlink($file); die('<return result="success" message="' . Tools::safeOutput(_PS_TMP_IMG_ . $tmp_name) . '" />'); } else { die('<return result="error" message="Cannot upload file" />'); } }
/** * Validate image upload (check image type and weight) * * @param array $file Upload $_FILE value * @param integer $max_file_size Maximum upload size * @return bool|string Return false if no error encountered */ public static function validateUpload($file, $max_file_size = 0) { if ((int) $max_file_size > 0 && $file['size'] > (int) $max_file_size) { return sprintf(Tools::displayError('Image is too large (%1$d kB). Maximum allowed: %2$d kB'), $file['size'] / 1000, $max_file_size / 1000); } if (!ImageManager::isRealImage($file['tmp_name'], $file['type']) || !ImageManager::isCorrectImageFileExt($file['name'])) { return Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png'); } if ($file['error']) { return sprintf(Tools::displayError('Error while uploading image; please change your server\'s settings. (Error code: %s)'), $file['error']); } return false; }
private function _postValidation() { $yalign = Tools::getValue('yalign'); $xalign = Tools::getValue('xalign'); $transparency = (int) Tools::getValue('transparency'); $image_types = Tools::getValue('image_types'); if (empty($transparency)) { $this->_postErrors[] = $this->l('Transparency required.'); } elseif ($transparency < 0 || $transparency > 100) { $this->_postErrors[] = $this->l('Transparency is not in allowed range.'); } if (empty($yalign)) { $this->_postErrors[] = $this->l('Y-Align is required.'); } elseif (!in_array($yalign, $this->yaligns)) { $this->_postErrors[] = $this->l('Y-Align is not in allowed range.'); } if (empty($xalign)) { $this->_postErrors[] = $this->l('X-Align is required.'); } elseif (!in_array($xalign, $this->xaligns)) { $this->_postErrors[] = $this->l('X-Align is not in allowed range.'); } if (empty($image_types)) { $this->_postErrors[] = $this->l('At least one image type is required.'); } if (isset($_FILES['PS_WATERMARK']['tmp_name']) && !empty($_FILES['PS_WATERMARK']['tmp_name'])) { if (!ImageManager::isRealImage($_FILES['PS_WATERMARK']['tmp_name'], $_FILES['PS_WATERMARK']['type'], array('image/gif'))) { $this->_postErrors[] = $this->l('Image must be in GIF format.'); } } return !count($this->_postErrors) ? true : false; }
private function _postValidation() { $yalign = Tools::getValue('yalign'); $xalign = Tools::getValue('xalign'); $transparency = (int) Tools::getValue('transparency'); $types = ImageType::getImagesTypes('products'); $id_image_type = array(); foreach ($types as $type) { if (!is_null(Tools::getValue('WATERMARK_TYPES_' . (int) $type['id_image_type']))) { $id_image_type['WATERMARK_TYPES_' . (int) $type['id_image_type']] = true; } } if (empty($transparency)) { $this->_postErrors[] = $this->l('Opacity required.'); } elseif ($transparency < 1 || $transparency > 100) { $this->_postErrors[] = $this->l('Opacity is not in allowed range.'); } if (empty($yalign)) { $this->_postErrors[] = $this->l('Y-Align is required.'); } elseif (!in_array($yalign, $this->yaligns)) { $this->_postErrors[] = $this->l('Y-Align is not in allowed range.'); } if (empty($xalign)) { $this->_postErrors[] = $this->l('X-Align is required.'); } elseif (!in_array($xalign, $this->xaligns)) { $this->_postErrors[] = $this->l('X-Align is not in allowed range.'); } if (!count($id_image_type)) { $this->_postErrors[] = $this->l('At least one image type is required.'); } if (isset($_FILES['PS_WATERMARK']['tmp_name']) && !empty($_FILES['PS_WATERMARK']['tmp_name'])) { if (!ImageManager::isRealImage($_FILES['PS_WATERMARK']['tmp_name'], $_FILES['PS_WATERMARK']['type'], array('image/gif'))) { $this->_postErrors[] = $this->l('Image must be in GIF format.'); } } return !count($this->_postErrors) ? true : false; }