示例#1
0
 public function checkPostFieldData($data, &$message, $entry_id = null)
 {
     if (is_array($data) && isset($data['name']) && $this->get('unique') == 'yes') {
         $data['name'] = $this->getUniqueFilename($data['name']);
     }
     // run basic upload check
     $error = parent::checkPostFieldData($data, $message, $entry_id);
     // test for minimum dimensions
     if ($error == self::__OK__) {
         // new file
         if (is_array($data)) {
             $tmp_name = $data['tmp_name'];
             $type = $data['type'];
         } else {
             if (is_string($data)) {
                 $tmp_name = WORKSPACE . $data;
                 $type = 'image/jpg';
                 // send some dummy data
             }
         }
         $meta = static::getMetaInfo($tmp_name, $type);
         // If we found some dimensions
         if (isset($meta['width']) && isset($meta['height'])) {
             $min_width = $this->get('min_width');
             $min_height = $this->get('min_height');
             $max_width = $this->get('max_width');
             $max_height = $this->get('max_height');
             // Min width
             if (!empty($min_width) && $min_width != 0 && $meta['width'] < $min_width) {
                 if (strlen($message) > 0) {
                     $message .= '<br />';
                 }
                 $message .= __('Image must have a minimum width of %1$spx.', array($min_width));
                 $error = self::__ERROR_CUSTOM__;
             }
             // Min height
             if (!empty($min_height) && $min_height != 0 && $meta['height'] < $min_height) {
                 if (strlen($message) > 0) {
                     $message .= '<br />';
                 }
                 $message .= __('Image must have a minimum height of %1$spx.', array($min_height));
                 $error = self::__ERROR_CUSTOM__;
             }
             // Check max only if resize is not active
             if (!$this->isResizeActive()) {
                 // Max width
                 if (!empty($max_width) && $max_width != 0 && $meta['width'] > $max_width) {
                     if (strlen($message) > 0) {
                         $message .= '<br />';
                     }
                     $message .= __('Image must have a maximum width of %1$spx.', array($max_width));
                     $error = self::__ERROR_CUSTOM__;
                 }
                 // Max height
                 if (!empty($max_height) && $max_height != 0 && $meta['height'] > $max_height) {
                     if (strlen($message) > 0) {
                         $message .= '<br />';
                     }
                     $message .= __('Image must have a maximum height of %1$spx.', array($max_height));
                     $error = self::__ERROR_CUSTOM__;
                 }
             }
         } else {
             if (is_array($data) && !empty($data['tmp_name'])) {
                 $message .= __('Uploaded file is not an image.');
                 $error = self::__ERROR_CUSTOM__;
             }
         }
     }
     return $error;
 }
 public function checkPostFieldData($data, &$message, $entry_id = NULL)
 {
     $error = self::__OK__;
     $field_data = $data;
     foreach (FLang::instance()->ld()->languageCodes() as $language_code) {
         $file_message = '';
         $data = $this->_getData($field_data[$language_code]);
         if ($this->get('unique') == 'yes' && is_array($data) && isset($data['name'])) {
             $data['name'] = $this->_getUniqueFilename($data['name'], $language_code);
         }
         $status = parent::checkPostFieldData($data, $file_message, $entry_id);
         if ($status != self::__OK__) {
             $message .= "<br />{$language_code}: {$file_message}";
             $error = self::__ERROR__;
         }
     }
     return $error;
 }