File

class \TYPO3\CMS\Core\Resource\File

Extends
AbstractFile

File representation in the file abstraction layer.

Table of Contents

Constants

FILETYPE_APPLICATION  : mixed = 5
Any kind of application
FILETYPE_AUDIO  : mixed = 3
Any kind of audio file
FILETYPE_IMAGE  : mixed = 2
Any kind of image
FILETYPE_TEXT  : mixed = 1
Any kind of text
FILETYPE_UNKNOWN  : mixed = 0
any other file
FILETYPE_VIDEO  : mixed = 4
Any kind of video

Properties

$deleted  : bool
If set to true, this file is regarded as being deleted.
$identifier  : string
The identifier of this file to identify it on the storage.
$name  : string
The file name of this file
$properties  : array
Various file properties
$storage  : ResourceStorage|null
The storage this file is located in
$updatedProperties  : array
Contains the names of all properties that have been update since the instantiation of this object

Methods

__construct()  : mixed
Constructor for a file object. Should normally not be used directly, use the corresponding factory methods instead.
_getPropertyRaw()  : mixed
calculateChecksum()  : string
Creates a MD5 hash checksum based on the combined identifier of the file, the files' mimetype and the systems' encryption key.
checkActionPermission()  : bool
Check if a file operation (= action) is allowed for this file
copyTo()  : File
Copies this file into a target folder
delete()  : bool
Deletes this file from its storage. This also means that this object becomes useless.
exists()  : bool
Checks if this file exists. This should normally always return TRUE; it might only return FALSE when this object has been created from an index record without checking for.
getCombinedIdentifier()  : string
Returns a combined identifier of this file, i.e. the storage UID and the folder identifier separated by a colon ":".
getContents()  : string
Get the contents of this file
getCreationTime()  : int
Returns the creation time of the file as Unix timestamp
getExtension()  : string
Get the extension of this file in a lower-case variant
getForLocalProcessing()  : string
Returns a path to a local version of this file to process it locally (e.g. with some system tool).
getHashedIdentifier()  : string
Get hashed identifier
getIdentifier()  : string
Returns the identifier of this file
getMetaData()  : MetaDataAspect
Loads the metadata of a file in an encapsulated aspect
getMimeType()  : string
Get the MIME type of this file
getModificationTime()  : int
Returns the date (as UNIX timestamp) the file was last modified.
getName()  : string
Returns the name of this file
getNameWithoutExtension()  : string
Returns the basename (the name without extension) of this file.
getParentFolder()  : FolderInterface
Returns the parent folder.
getProperties()  : array
Returns the properties of this object.
getProperty()  : mixed
Returns a property value
getPublicUrl()  : string|null
Returns a publicly accessible URL for this file When file is marked as missing or deleted no url is returned
getSha1()  : string
Gets SHA1 hash.
getSize()  : int|null
Returns the size of this file
getStorage()  : ResourceStorage
Get the storage this file is located in
getType()  : int
Returns the fileType of this file basically there are only five main "file types" "audio" "image" "software" "text" "video" "other" see the constants in this class
getUid()  : int
Returns the uid of this file
getUpdatedProperties()  : array
Returns the names of all properties that have been updated in this record
hasProperty()  : bool
Checks if the file has a (metadata) property which can be retrieved by "getProperty"
isDeleted()  : bool
Returns TRUE if this file has been deleted
isImage()  : bool
Useful to find out if this file can be previewed or resized as image.
isIndexed()  : bool|null
Returns TRUE if this file is indexed
isMediaFile()  : bool
Useful to find out if this file has a file extension based on any of the registered media extensions
isMissing()  : bool
isTextFile()  : bool
Useful to find out if this file can be edited.
moveTo()  : File
Moves the file into the target folder
process()  : ProcessedFile
Returns a modified version of the file.
rename()  : FileInterface
Renames this file.
setContents()  : File
Replace the current file contents with the given string
setDeleted()  : mixed
Marks this file as deleted. This should only be used inside the File Abstraction Layer, as it is a low-level API method.
setIdentifier()  : File
Set the identifier of this file
setMissing()  : mixed
setStorage()  : File
Sets the storage this file is located in. This is only meant for \TYPO3\CMS\Core\Resource-internal usage; don't use it to move files.
toArray()  : array
Returns an array representation of the file.
updateProperties()  : mixed
Updates the properties of this file, e.g. after re-indexing or moving it.

Constants

FILETYPE_UNKNOWN

any other file

public mixed FILETYPE_UNKNOWN = 0

Properties

$deleted

If set to true, this file is regarded as being deleted.

protected bool $deleted = false

$identifier

The identifier of this file to identify it on the storage.

protected string $identifier

On some drivers, this is the path to the file, but drivers could also just provide any other unique identifier for this file on the specific storage.

$name

The file name of this file

protected string $name

$properties

Various file properties

protected array $properties

Note that all properties, which only the persisted (indexed) files have are stored in this overall properties array only. The only properties which really exist as object properties of the file object are the storage, the identifier, the fileName and the indexing status.

$updatedProperties

Contains the names of all properties that have been update since the instantiation of this object

protected array $updatedProperties = []

Methods

__construct()

Constructor for a file object. Should normally not be used directly, use the corresponding factory methods instead.

public __construct(array $fileData, ResourceStorage $storage[, array $metaData = [] ]) : mixed

Parameters

$fileData : array
$storage : ResourceStorage
$metaData : array = []

_getPropertyRaw()

public _getPropertyRaw(string $key) : mixed

Parameters

$key : string

calculateChecksum()

Creates a MD5 hash checksum based on the combined identifier of the file, the files' mimetype and the systems' encryption key.

public calculateChecksum() : string

used to generate a thumbnail, and this hash is checked if valid

Return values

string —

the MD5 hash

checkActionPermission()

Check if a file operation (= action) is allowed for this file

public checkActionPermission(string $action) : bool

Parameters

$action : string

can be read, write, delete

Return values

bool

copyTo()

Copies this file into a target folder

public copyTo(Folder $targetFolder[, string $targetFileName = null ][, string $conflictMode = DuplicationBehavior::RENAME ]) : File

Parameters

$targetFolder : Folder

Folder to copy file into.

$targetFileName : string = null

an optional destination fileName

$conflictMode : string = DuplicationBehavior::RENAME

a value of the \TYPO3\CMS\Core\Resource\DuplicationBehavior enumeration

Tags

throws
RuntimeException

Return values

File —

The new (copied) file.

delete()

Deletes this file from its storage. This also means that this object becomes useless.

public delete() : bool

Return values

bool —

TRUE if deletion succeeded

exists()

Checks if this file exists. This should normally always return TRUE; it might only return FALSE when this object has been created from an index record without checking for.

public exists() : bool

Return values

bool —

TRUE if this file physically exists

getCombinedIdentifier()

Returns a combined identifier of this file, i.e. the storage UID and the folder identifier separated by a colon ":".

public getCombinedIdentifier() : string

Return values

string —

Combined storage and file identifier, e.g. StorageUID:path/and/fileName.png

getContents()

Get the contents of this file

public getContents() : string

Return values

string —

File contents

getCreationTime()

Returns the creation time of the file as Unix timestamp

public getCreationTime() : int

Tags

throws
RuntimeException

Return values

int

getExtension()

Get the extension of this file in a lower-case variant

public getExtension() : string

Return values

string —

The file extension

getForLocalProcessing()

Returns a path to a local version of this file to process it locally (e.g. with some system tool).

public getForLocalProcessing([bool $writable = true ]) : string

If the file is normally located on a remote storages, this creates a local copy. If the file is already on the local system, this only makes a new copy if $writable is set to TRUE.

Parameters

$writable : bool = true

Set this to FALSE if you only want to do read operations on the file.

Tags

throws
RuntimeException

Return values

string

getHashedIdentifier()

Get hashed identifier

public getHashedIdentifier() : string

Return values

string

getIdentifier()

Returns the identifier of this file

public getIdentifier() : string

Return values

string

getMimeType()

Get the MIME type of this file

public getMimeType() : string

Return values

string —

mime type

getModificationTime()

Returns the date (as UNIX timestamp) the file was last modified.

public getModificationTime() : int

Tags

throws
RuntimeException

Return values

int

getName()

Returns the name of this file

public getName() : string

Return values

string

getNameWithoutExtension()

Returns the basename (the name without extension) of this file.

public getNameWithoutExtension() : string

Return values

string

getProperties()

Returns the properties of this object.

public getProperties() : array

Return values

array

getProperty()

Returns a property value

public getProperty(string $key) : mixed

Parameters

$key : string

Return values

mixed —

Property value

getPublicUrl()

Returns a publicly accessible URL for this file When file is marked as missing or deleted no url is returned

public getPublicUrl([bool $relativeToCurrentScript = false ]) : string|null

WARNING: Access to the file may be restricted by further means, e.g. some web-based authentication. You have to take care of this yourself.

Parameters

$relativeToCurrentScript : bool = false

Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver). Deprecated since TYPO3 v11, will be removed in TYPO3 v12.0

Return values

string|null —

NULL if file is missing or deleted, the generated url otherwise

getSha1()

Gets SHA1 hash.

public getSha1() : string

Return values

string

getSize()

Returns the size of this file

public getSize() : int|null

Tags

throws
RuntimeException

Return values

int|null —

Returns null if size is not available for the file

getType()

Returns the fileType of this file basically there are only five main "file types" "audio" "image" "software" "text" "video" "other" see the constants in this class

public getType() : int

Return values

int —

$fileType

getUid()

Returns the uid of this file

public getUid() : int

Return values

int

getUpdatedProperties()

Returns the names of all properties that have been updated in this record

public getUpdatedProperties() : array

Return values

array

hasProperty()

Checks if the file has a (metadata) property which can be retrieved by "getProperty"

public hasProperty(string $key) : bool

Parameters

$key : string

Return values

bool

isDeleted()

Returns TRUE if this file has been deleted

public isDeleted() : bool

Return values

bool

isImage()

Useful to find out if this file can be previewed or resized as image.

public isImage() : bool

Return values

bool —

true if File has an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']

isIndexed()

Returns TRUE if this file is indexed

public isIndexed() : bool|null

Return values

bool|null

isMediaFile()

Useful to find out if this file has a file extension based on any of the registered media extensions

public isMediaFile() : bool

Return values

bool —

true if File is a media-extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']

isMissing()

public isMissing() : bool

Return values

bool

isTextFile()

Useful to find out if this file can be edited.

public isTextFile() : bool

Return values

bool —

true if File is a text-based file extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']

moveTo()

Moves the file into the target folder

public moveTo(Folder $targetFolder[, string $targetFileName = null ][, string $conflictMode = DuplicationBehavior::RENAME ]) : File

Parameters

$targetFolder : Folder

Folder to move file into.

$targetFileName : string = null

an optional destination fileName

$conflictMode : string = DuplicationBehavior::RENAME

a value of the \TYPO3\CMS\Core\Resource\DuplicationBehavior enumeration

Tags

throws
RuntimeException

Return values

File —

This file object, with updated properties.

process()

Returns a modified version of the file.

public process(string $taskType, array $configuration) : ProcessedFile

Parameters

$taskType : string

The task type of this processing

$configuration : array

the processing configuration, see manual for that

Return values

ProcessedFile —

The processed file

setContents()

Replace the current file contents with the given string

public setContents(string $contents) : File

Parameters

$contents : string

The contents to write to the file.

Return values

File —

The file object (allows chaining).

setDeleted()

Marks this file as deleted. This should only be used inside the File Abstraction Layer, as it is a low-level API method.

public setDeleted() : mixed

setIdentifier()

Set the identifier of this file

public setIdentifier(string $identifier) : File

Parameters

$identifier : string

Return values

File

setMissing()

public setMissing(bool $missing) : mixed

Parameters

$missing : bool

setStorage()

Sets the storage this file is located in. This is only meant for \TYPO3\CMS\Core\Resource-internal usage; don't use it to move files.

public setStorage(ResourceStorage $storage) : File

Parameters

$storage : ResourceStorage

Return values

File

toArray()

Returns an array representation of the file.

public toArray() : array

(This is used by the generic listing module vidi when displaying file records.)

Return values

array —

Array of main data of the file. Don't rely on all data to be present here, it's just a selection of the most relevant information.

updateProperties()

Updates the properties of this file, e.g. after re-indexing or moving it.

public updateProperties(array $properties) : mixed

By default, only properties that exist as a key in the $properties array are overwritten. If you want to explicitly unset a property, set the corresponding key to NULL in the array.

NOTE: This method should not be called from outside the File Abstraction Layer (FAL)!

Parameters

$properties : array
On this page