You are here

public function FileUploadSanitizeNameEvent::setFilename in Drupal 10

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php \Drupal\Core\File\Event\FileUploadSanitizeNameEvent::setFilename()

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;
}