public function ExtractFileValidator::isFileSizeAllowed in Search API attachments 9.0.x
Same name and namespace in other branches
- 8 src/ExtractFileValidator.php \Drupal\search_api_attachments\ExtractFileValidator::isFileSizeAllowed()
Exclude files that exceed configured max size.
Parameters
object $file: File object.
int $max_filesize: Max allowed file size.
Return value
bool TRUE if the file size does not exceed configured max size.
File
- src/
ExtractFileValidator.php, line 79
Class
- ExtractFileValidator
- Validator class for attachment indexing.
Namespace
Drupal\search_api_attachmentsCode
public function isFileSizeAllowed($file, $max_filesize = 0) {
if (!empty($max_filesize)) {
$configured_size = $max_filesize;
if ($configured_size == '0') {
return TRUE;
}
else {
$file_size_bytes = $file
->getSize();
$configured_size_bytes = Bytes::toInt($configured_size);
if ($file_size_bytes > $configured_size_bytes) {
return FALSE;
}
}
}
return TRUE;
}