Symfony\Component\HttpFoundation\File\File::guessExtension PHP Method

guessExtension() public method

If the mime type is unknown, returns null.
public guessExtension ( ) : string | null
return string | null The guessed extension or null if it cannot be guessed
    public function guessExtension()
    {
        $type = $this->getMimeType();
        $guesser = ExtensionGuesser::getInstance();

        return $guesser->guess($type);
    }

Usage Example

 public function preUpload()
 {
     if (null !== $this->photo_file) {
         // do whatever you want to generate a unique name
         $this->nom = $this->getUser()->getUsername() . '.' . $this->photo_file->guessExtension();
     }
 }
All Usage Examples Of Symfony\Component\HttpFoundation\File\File::guessExtension