protected function validate($uploaded_file, $file, $error, $index) { if ($error) { $file->error = $this->get_error_message($error); return false; } $content_length = $this->fix_integer_overflow($this->get_server_var('CONTENT_LENGTH')); $post_max_size = $this->get_config_bytes(ini_get('post_max_size')); if ($post_max_size && $content_length > $post_max_size) { $file->error = $this->get_error_message('post_max_size'); return false; } if (!$this->fm->is_allowed_file_type($file->name)) { $file->error = $this->get_error_message('accept_file_types'); return false; } if ($uploaded_file && is_uploaded_file($uploaded_file)) { $file_size = $this->get_file_size($uploaded_file); } else { $file_size = $content_length; } if ($this->fm->config['options']['fileRootSizeLimit'] > 0 && $file_size + $this->fm->getRootTotalSize() > $this->fm->config['options']['fileRootSizeLimit']) { $file->error = $this->get_error_message('max_storage_size'); return false; } if ($this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] || $file->size > $this->options['max_file_size'])) { $file->error = $this->get_error_message('max_file_size'); return false; } if ($this->options['min_file_size'] && $file_size < $this->options['min_file_size']) { $file->error = $this->get_error_message('min_file_size'); return false; } if (is_int($this->options['max_number_of_files']) && $this->count_file_objects() >= $this->options['max_number_of_files'] && !is_file($this->get_upload_path($file->name))) { $file->error = $this->get_error_message('max_number_of_files'); return false; } if ($this->fmData['images_only'] && !$this->is_valid_image_file($uploaded_file)) { $file->error = sprintf($this->fm->lang('UPLOAD_IMAGES_ONLY')); return false; } $max_width = @$this->options['max_width']; $max_height = @$this->options['max_height']; $min_width = @$this->options['min_width']; $min_height = @$this->options['min_height']; if (($max_width || $max_height || $min_width || $min_height) && preg_match($this->options['image_file_types'], $file->name)) { list($img_width, $img_height) = $this->get_image_size($uploaded_file); // If we are auto rotating the image by default, do the checks on // the correct orientation if (@$this->options['image_versions']['']['auto_orient'] && function_exists('exif_read_data') && ($exif = @exif_read_data($uploaded_file)) && (int) @$exif['Orientation'] >= 5) { $tmp = $img_width; $img_width = $img_height; $img_height = $tmp; unset($tmp); } } if (!empty($img_width)) { if ($max_width && $img_width > $max_width) { $file->error = $this->get_error_message('max_width'); return false; } if ($max_height && $img_height > $max_height) { $file->error = $this->get_error_message('max_height'); return false; } if ($min_width && $img_width < $min_width) { $file->error = $this->get_error_message('min_width'); return false; } if ($min_height && $img_height < $min_height) { $file->error = $this->get_error_message('min_height'); return false; } } return true; }