Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UploadedFile.php

class UploadedFile

Same name in this branch
  1. 11.1.x vendor/guzzlehttp/psr7/src/UploadedFile.php \GuzzleHttp\Psr7\UploadedFile
  2. 11.1.x vendor/symfony/http-foundation/File/UploadedFile.php \Symfony\Component\HttpFoundation\File\UploadedFile

@author Nicolas Grekas <p@tchwork.com>

Hierarchy

  • class \Symfony\Component\HttpFoundation\File\File extends \Symfony\Component\HttpFoundation\File\SplFileInfo
    • class \Symfony\Component\HttpFoundation\File\UploadedFile extends \Symfony\Component\HttpFoundation\File\File
      • class \Symfony\Bridge\PsrHttpMessage\Factory\UploadedFile extends \Symfony\Component\HttpFoundation\File\UploadedFile

Expanded class hierarchy of UploadedFile

File

vendor/symfony/psr-http-message-bridge/Factory/UploadedFile.php, line 22

Namespace

Symfony\Bridge\PsrHttpMessage\Factory
View source
class UploadedFile extends BaseUploadedFile {
    private bool $test = false;
    public function __construct(UploadedFileInterface $psrUploadedFile, callable $getTemporaryPath) {
        $error = $psrUploadedFile->getError();
        $path = '';
        if (\UPLOAD_ERR_NO_FILE !== $error) {
            $path = $psrUploadedFile->getStream()
                ->getMetadata('uri') ?? '';
            if ($this->test = !\is_string($path) || !is_uploaded_file($path)) {
                $path = $getTemporaryPath();
                $psrUploadedFile->moveTo($path);
            }
        }
        parent::__construct($path, (string) $psrUploadedFile->getClientFilename(), $psrUploadedFile->getClientMediaType(), $psrUploadedFile->getError(), $this->test);
    }
    public function move(string $directory, ?string $name = null) : File {
        if (!$this->isValid() || $this->test) {
            return parent::move($directory, $name);
        }
        $target = $this->getTargetFile($directory, $name);
        try {
            $this->psrUploadedFile
                ->moveTo((string) $target);
        } catch (\RuntimeException $e) {
            throw new FileException(\sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, $e->getMessage()), 0, $e);
        }
        @chmod($target, 0666 & ~umask());
        return $target;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
File::getContent public function
File::getMimeType public function Returns the mime type of the file.
File::getName protected function Returns locale independent base name of the given path.
File::getTargetFile protected function
File::guessExtension public function Returns the extension based on the mime type.
UploadedFile::$error private property
UploadedFile::$mimeType private property
UploadedFile::$originalName private property
UploadedFile::$originalPath private property
UploadedFile::$test private property
UploadedFile::getClientMimeType public function Returns the file mime type.
UploadedFile::getClientOriginalExtension public function Returns the original file extension.
UploadedFile::getClientOriginalName public function Returns the original file name.
UploadedFile::getClientOriginalPath public function Returns the original file full path.
UploadedFile::getError public function Returns the upload error.
UploadedFile::getErrorMessage public function Returns an informative upload error message.
UploadedFile::getMaxFilesize public static function Returns the maximum size of an uploaded file as configured in php.ini.
UploadedFile::guessClientExtension public function Returns the extension based on the client mime type.
UploadedFile::isValid public function Returns whether the file has been uploaded with HTTP and no error occurred.
UploadedFile::move public function Moves the file to a new location. Overrides UploadedFile::move
UploadedFile::parseFilesize private static function
UploadedFile::__construct public function Accepts the information of the uploaded file as provided by the PHP global $_FILES. Overrides UploadedFile::__construct

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal