File extends AbstractFile

File representation in the file abstraction layer.

Table of Contents

Constants

FILETYPE_APPLICATION  = 5
Any kind of application
FILETYPE_AUDIO  = 3
Any kind of audio file
FILETYPE_IMAGE  = 2
Any kind of image
FILETYPE_TEXT  = 1
Any kind of text
FILETYPE_UNKNOWN  = 0
any other file
FILETYPE_VIDEO  = 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<non-empty-string, mixed>
Various file properties
$storage  : ResourceStorage|null
The storage this file is located in
$updatedProperties  : array<string|int, mixed>
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()  : non-empty-string
Returns a path to a local version of this file to process it locally (e.g. with some system tool).
getHashedIdentifier()  : non-empty-string
getIdentifier()  : string
getMetaData()  : MetaDataAspect
Loads the metadata of a file in an encapsulated aspect
getMimeType()  : non-empty-string
Get the MIME type of this file
getModificationTime()  : int
Returns the date (as UNIX timestamp) the file was last modified.
getName()  : string
getNameWithoutExtension()  : string
Returns the basename (the name without extension) of this file.
getParentFolder()  : FolderInterface
getProperties()  : array<non-empty-string, mixed>
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()  : non-empty-string
Gets SHA1 hash.
getSize()  : int<0, max>
MUST return the size of the file as unsigned int i.e. 0-max.
getStorage()  : ResourceStorage
getType()  : int
Returns the fileType of this file basically there are only five main "file types" "audio" "image" "software" "text" "video" "other" see FileType enum
getUid()  : int
Returns the uid of this file
getUpdatedProperties()  : array<string|int, mixed>
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
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.
isType()  : bool
moveTo()  : File
Moves the file into the target folder
process()  : ProcessedFile
Returns a modified version of the file.
rename()  : FileInterface
Renames this file.
setContents()  : $this
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()  : $this
Set the identifier of this file
setMissing()  : mixed
setStorage()  : $this
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<non-empty-string, mixed>
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

Deprecated

will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::UNKNOWN instead

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<non-empty-string, mixed> $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<string|int, mixed> $updatedProperties = []

Methods

__construct()

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

public __construct(array<string|int, mixed> $fileData, ResourceStorage $storage[, array<string|int, mixed> $metaData = [] ]) : mixed
Parameters
$fileData : array<string|int, mixed>
$storage : ResourceStorage
$metaData : array<string|int, mixed> = []

_getPropertyRaw()

public _getPropertyRaw(string $key) : mixed
Parameters
$key : string
Internal

Only for use in Repositories and indexer

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|DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : File
Parameters
$targetFolder : Folder

Folder to copy file into.

$targetFileName : string = null

an optional destination fileName

$conflictMode : string|DuplicationBehavior = DuplicationBehavior::RENAME
Tags
throws
RuntimeException
todo

change $conflictMode parameter type to DuplicationBehavior in TYPO3 v14.0

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

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

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

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 ]) : non-empty-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
non-empty-string

getHashedIdentifier()

public getHashedIdentifier() : non-empty-string
Return values
non-empty-string

getIdentifier()

public getIdentifier() : string
Return values
string

getMimeType()

Get the MIME type of this file

public getMimeType() : non-empty-string
Return values
non-empty-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()

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<non-empty-string, mixed>
Return values
array<non-empty-string, mixed>

getProperty()

Returns a property value

public getProperty(non-empty-string $key) : mixed
Parameters
$key : non-empty-string

getPublicUrl()

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

public getPublicUrl() : 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.

Return values
string|null

NULL if file is deleted, the generated URL otherwise

getSha1()

Gets SHA1 hash.

public getSha1() : non-empty-string
Return values
non-empty-string

getSize()

MUST return the size of the file as unsigned int i.e. 0-max.

public getSize() : int<0, max>
Tags
throws
RuntimeException
Return values
int<0, max>

getType()

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

public getType() : int
Tags
todo

will return an instance of FileType enum in TYPO3 v14.0

Attributes
#[ReturnTypeWillChange]
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<string|int, mixed>
Return values
array<string|int, mixed>

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
Return values
bool

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|DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : File
Parameters
$targetFolder : Folder

Folder to move file into.

$targetFileName : string = null

an optional destination fileName

$conflictMode : string|DuplicationBehavior = DuplicationBehavior::RENAME
Tags
throws
RuntimeException
todo

change $conflictMode parameter type to DuplicationBehavior in TYPO3 v14.0

Return values
File

This file object, with updated properties.

process()

Returns a modified version of the file.

public process(string $taskType, array<string|int, mixed> $configuration) : ProcessedFile
Parameters
$taskType : string

The task type of this processing

$configuration : array<string|int, mixed>

the processing configuration, see manual for that

Return values
ProcessedFile

rename()

Renames this file.

public rename(non-empty-string $newName[, string|DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : FileInterface
Parameters
$newName : non-empty-string

The new file name

$conflictMode : string|DuplicationBehavior = DuplicationBehavior::RENAME
Tags
todo

change $conflictMode parameter type to DuplicationBehavior in TYPO3 v14.0

Return values
FileInterface

setContents()

Replace the current file contents with the given string

public setContents(string $contents) : $this
Parameters
$contents : string
Return values
$this

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) : $this
Parameters
$identifier : string
Internal

Should only be used by other parts of the File API (e.g. drivers after moving a file)

Return values
$this

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) : $this
Parameters
$storage : ResourceStorage
Internal

Should only be used by other parts of the File API (e.g. drivers after moving a file)

Return values
$this

toArray()

Returns an array representation of the file.

public toArray() : array<non-empty-string, mixed>

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

Return values
array<non-empty-string, mixed>

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<string|int, mixed> $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<string|int, mixed>
Internal

        
On this page

Search results