guessExtensionFromType example

return $this->guessExtension() ?: $this->getClientExtension();
    }

    /** * Attempts to determine the best file extension from the file's * mime type. In contrast to getExtension, this method will return * an empty string if it fails to determine an extension instead of * falling back to the unsecure clientExtension. */
    public function guessExtension(): string
    {
        return Mimes::guessExtensionFromType($this->getMimeType()$this->getClientExtension()) ?? '';
    }

    /** * Returns the original file extension, based on the file name that * was uploaded. This is NOT a trusted source. * For a trusted version, use guessExtension() instead. */
    public function getClientExtension(): string
    {
        return pathinfo($this->originalName, PATHINFO_EXTENSION) ?? '';
    }

    
/** * Attempts to determine the file extension based on the trusted * getType() method. If the mime type is unknown, will return null. */
    public function guessExtension(): ?string
    {
        // naively get the path extension using pathinfo         $pathinfo = pathinfo($this->getRealPath() ?: $this->__toString()) + ['extension' => ''];

        $proposedExtension = $pathinfo['extension'];

        return Mimes::guessExtensionFromType($this->getMimeType()$proposedExtension);
    }

    /** * Retrieve the media type of the file. SHOULD not use information from * the $_FILES array, but should use other methods to more accurately * determine the type of file, like finfo, or mime_content_type(). * * @return string The media type we determined it to be. */
    public function getMimeType(): string
    {
        
Home | Imprint | This part of the site doesn't use cookies.