Index: branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php =================================================================== diff -u -N -r14588 -r14611 --- branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 14588) +++ branches/5.2.x/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 14611) @@ -1,6 +1,6 @@ GetFieldOptions($field_name); @@ -123,8 +124,17 @@ if (is_array($value) && $value['error'] === UPLOAD_ERR_OK) { $max_filesize = isset($options['max_size']) ? $options['max_size'] : MAX_UPLOAD_SIZE; - if (getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types'])) { + if ( getArrayValue($options, 'file_types') && !$this->extensionMatch($value['name'], $options['file_types']) ) { + // match by file extensions $error_params = Array ( + 'file_name' => $value['name'], + 'file_types' => $options['file_types'], + ); + $object->SetError($field_name, 'bad_file_format', 'la_error_InvalidFileFormat', $error_params); + } + elseif (getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types'])) { + // match by mime type provided by web-browser + $error_params = Array ( 'file_type' => $value['type'], 'allowed_types' => $options['allowed_types'], ); @@ -175,6 +185,26 @@ return $ret; } + /** + * Checks, that given file name has on of provided file extensions + * + * @param string $filename + * @param string $file_types + * @return bool + * @access protected + */ + protected function extensionMatch($filename, $file_types) + { + if ( preg_match_all('/\*\.(.*?)(;|$)/', $file_types, $regs) ) { + $file_extension = mb_strtolower( pathinfo($filename, PATHINFO_EXTENSION) ); + $file_extensions = array_map('mb_strtolower', $regs[1]); + + return in_array($file_extension, $file_extensions); + } + + return true; + } + function getSingleFormat($format) { $single_mapping = Array ( @@ -194,7 +224,7 @@ * * @param string $value * @param string $field_name - * @param kDBItem $object + * @param kDBItem|kDBList $object * @param string $format * @return string */