function FileUploadResource::prepareFilename

Same name in other branches
  1. 9 core/modules/file/src/Plugin/rest/resource/FileUploadResource.php \Drupal\file\Plugin\rest\resource\FileUploadResource::prepareFilename()
  2. 8.9.x core/modules/file/src/Plugin/rest/resource/FileUploadResource.php \Drupal\file\Plugin\rest\resource\FileUploadResource::prepareFilename()

Prepares the filename to strip out any malicious extensions.

Parameters

string $filename: The file name.

array $validators: The array of upload validators.

Return value

string The prepared/munged filename.

Deprecated

in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement.

See also

https://www.drupal.org/node/3402032

https://www.drupal.org/node/3402032

File

core/modules/file/src/Plugin/rest/resource/FileUploadResource.php, line 372

Class

FileUploadResource
File upload resource.

Namespace

Drupal\file\Plugin\rest\resource

Code

protected function prepareFilename($filename, array &$validators) {
    @\trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3402032', E_USER_DEPRECATED);
    $extensions = $validators['FileExtension']['extensions'] ?? '';
    $event = new FileUploadSanitizeNameEvent($filename, $extensions);
    // @phpstan-ignore-next-line
    $this->eventDispatcher
        ->dispatch($event);
    return $event->getFilename();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.