You are here

protected function MediaBulkUploadForm::validateFileSize in Media Bulk Upload 8

Check the size of a file.

Parameters

\Drupal\media\MediaTypeInterface $mediaType: Media Type.

string $filePath: File path.

Return value

bool True if max size for a given file do not exceeds max size for its type.

1 call to MediaBulkUploadForm::validateFileSize()
MediaBulkUploadForm::processFile in src/Form/MediaBulkUploadForm.php
Process a file upload.

File

src/Form/MediaBulkUploadForm.php, line 441

Class

MediaBulkUploadForm
Class BulkMediaUploadForm.

Namespace

Drupal\media_bulk_upload\Form

Code

protected function validateFileSize(MediaTypeInterface $mediaType, $filePath) {
  $fileSizeSetting = $this->mediaSubFormManager
    ->getMediaTypeManager()
    ->getTargetFieldMaxSize($mediaType);
  $fileSize = filesize($filePath);
  $maxFileSize = !empty($fileSizeSetting) ? Bytes::toInt($fileSizeSetting) : Environment::getUploadMaxSize();
  if ($maxFileSize == 0) {
    return true;
  }
  return $fileSize <= $maxFileSize;
}