You are here

public function FileUploadSanitizeNameEvent::setFilename in Drupal 9

Sets the filename.

Parameters

string $filename: The filename to use for the uploaded file.

Return value

$this

Throws

\InvalidArgumentException Thrown when $filename contains path information.

1 call to FileUploadSanitizeNameEvent::setFilename()
FileUploadSanitizeNameEvent::__construct in core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php
Constructs a file upload sanitize name event object.

File

core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php, line 73

Class

FileUploadSanitizeNameEvent
An event during file upload that lets subscribers sanitize the filename.

Namespace

Drupal\Core\File\Event

Code

public function setFilename(string $filename) : self {
  if (dirname($filename) !== '.') {
    throw new \InvalidArgumentException(sprintf('$filename must be a filename with no path information, "%s" provided', $filename));
  }
  $this->filename = $filename;
  return $this;
}