function FileEventSubscriber::ensureValidUtf8Filename
Same name and namespace in other branches
- 11.x core/modules/file/src/EventSubscriber/FileEventSubscriber.php \Drupal\file\EventSubscriber\FileEventSubscriber::ensureValidUtf8Filename()
Guarantees a valid UTF-8 filename for subsequent event handlers.
Parameters
\Drupal\Core\File\Event\FileUploadSanitizeNameEvent $event: File upload sanitize name event.
File
-
core/
modules/ file/ src/ EventSubscriber/ FileEventSubscriber.php, line 58
Class
- FileEventSubscriber
- Sanitizes uploaded filenames.
Namespace
Drupal\file\EventSubscriberCode
public function ensureValidUtf8Filename(FileUploadSanitizeNameEvent $event) : void {
$filename = $event->getFilename();
if (!mb_check_encoding($filename, 'UTF-8')) {
$replacement = $this->configFactory
->get('file.settings')
->get('filename_sanitization.replacement_character');
$event->setFilename(self::coerceToValidUtf8($filename, $replacement));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.