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<string|int, 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() : 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<string|int, 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() : 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<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|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<string|int, 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_APPLICATION
Any kind of application
public
mixed
FILETYPE_APPLICATION
= 5
Tags
FILETYPE_AUDIO
Any kind of audio file
public
mixed
FILETYPE_AUDIO
= 3
Tags
FILETYPE_IMAGE
Any kind of image
public
mixed
FILETYPE_IMAGE
= 2
Tags
FILETYPE_TEXT
Any kind of text
public
mixed
FILETYPE_TEXT
= 1
Tags
FILETYPE_UNKNOWN
any other file
public
mixed
FILETYPE_UNKNOWN
= 0
FILETYPE_VIDEO
Any kind of video
public
mixed
FILETYPE_VIDEO
= 4
Tags
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<string|int, 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.
$storage
The storage this file is located in
protected
ResourceStorage|null
$storage
$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
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
boolcopyTo()
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
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
Return values
intgetExtension()
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
Return values
stringgetHashedIdentifier()
Get hashed identifier
public
getHashedIdentifier() : string
Return values
stringgetIdentifier()
Returns the identifier of this file
public
getIdentifier() : string
Return values
stringgetMetaData()
Loads the metadata of a file in an encapsulated aspect
public
getMetaData() : MetaDataAspect
Return values
MetaDataAspectgetMimeType()
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
Return values
intgetName()
Returns the name of this file
public
getName() : string
Return values
stringgetNameWithoutExtension()
Returns the basename (the name without extension) of this file.
public
getNameWithoutExtension() : string
Return values
stringgetParentFolder()
Returns the parent folder.
public
getParentFolder() : FolderInterface
Return values
FolderInterfacegetProperties()
Returns the properties of this object.
public
getProperties() : array<string|int, mixed>
Return values
array<string|int, mixed>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
stringgetSize()
Returns the size of this file
public
getSize() : int|null
Tags
Return values
int|null —Returns null if size is not available for the file
getStorage()
Get the storage this file is located in
public
getStorage() : ResourceStorage
Tags
Return values
ResourceStoragegetType()
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
intgetUpdatedProperties()
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
boolisDeleted()
Returns TRUE if this file has been deleted
public
isDeleted() : bool
Return values
boolisImage()
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|nullisMediaFile()
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
boolisTextFile()
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
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 —The processed file
rename()
Renames this file.
public
rename(string $newName[, string $conflictMode = DuplicationBehavior::RENAME ]) : FileInterface
Parameters
- $newName : string
-
The new file name
- $conflictMode : string = DuplicationBehavior::RENAME
Return values
FileInterfacesetContents()
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
Should only be used by other parts of the File API (e.g. drivers after moving a file)
Return values
FilesetMissing()
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
Should only be used by other parts of the File API (e.g. drivers after moving a file)
Return values
FiletoArray()
Returns an array representation of the file.
public
toArray() : array<string|int, mixed>
(This is used by the generic listing module vidi when displaying file records.)
Return values
array<string|int, 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>