Symfony API
Class

Symfony\Component\HttpFoundation\File\File

class File extends SplFileInfo

A file in the file system.

Methods

__construct(string $path, bool $checkPath = true)

Constructs a new file from the given path.

string|null guessExtension()

Returns the extension based on the mime type.

string|null getMimeType()

Returns the mime type of the file.

File move(string $directory, string $name = null)

Moves the file to a new location.

Details

at line 34
public __construct(string $path, bool $checkPath = true)

Constructs a new file from the given path.

Parameters

string $path The path to the file
bool $checkPath Whether to check the path or not

Exceptions

FileNotFoundException If the given path is not a file

at line 56
public string|null guessExtension()

Returns the extension based on the mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getMimeType() to guess the file extension.

Return Value

string|null The guessed extension or null if it cannot be guessed

See also

ExtensionGuesser
getMimeType()

at line 75
public string|null getMimeType()

Returns the mime type of the file.

The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(), mimecontenttype() and the system binary "file" (in this order), depending on which of those are available.

Return Value

string|null The guessed mime type (i.e. "application/pdf")

See also

MimeTypeGuesser

at line 92
public File move(string $directory, string $name = null)

Moves the file to a new location.

Parameters

string $directory The destination folder
string $name The new file name

Return Value

File A File object representing the new file

Exceptions

FileException if the target file could not be created