ResourceStorage

class \TYPO3\CMS\Core\Resource\ResourceStorage

Implements
ResourceStorageInterface

A "mount point" inside the TYPO3 file handling.

A "storage" object handles

  • abstraction to the driver
  • permissions (from the driver, and from the user, + capabilities)
  • an entry point for files, folders, and for most other operations

== Driver entry point The driver itself, that does the actual work on the file system, is inside the storage but completely shadowed by the storage, as the storage also handles the abstraction to the driver

The storage can be on the local system, but can also be on a remote system. The combination of driver + configurable capabilities (storage is read-only e.g.) allows for flexible uses.

== Permission system As all requests have to run through the storage, the storage knows about the permissions of a BE/FE user, the file permissions / limitations of the driver and has some configurable capabilities. Additionally, a BE user can use "file mounts" (known from previous installations) to limit his/her work-zone to only a subset (identifier and its subfolders/subfolders) of the user itself.

Check 1: "User Permissions" [is the user allowed to write a file) [is the user allowed to write a file] Check 2: "File Mounts" of the User (act as subsets / filters to the identifiers) [is the user allowed to do something in this folder?] Check 3: "Capabilities" of Storage (then: of Driver) [is the storage/driver writable?] Check 4: "File permissions" of the Driver [is the folder writable?]

Table of Contents

Interfaces

ResourceStorageInterface
The interface for a resource storage containing all constants

Constants

PROCESSING_FOLDER_LEVELS  : mixed = 2
Levels numbers used to generate hashed subfolders in the processing folder

Properties

$capabilities  : Capabilities
The capabilities of this storage as defined in the storage record.
$configuration  : array
The configuration belonging to this storage (decoded from the configuration field).
$driver  : DriverInterface
$evaluatePermissions  : bool
Whether to check if file or folder is in user mounts and the action is allowed for a user Default is FALSE so that resources are accessible for front end rendering or admins.
$eventDispatcher  : EventDispatcherInterface
$fileAndFolderNameFilters  : array
The filters used for the files and folder names.
$fileMounts  : array
User file mounts, added as an array, and used as filters
$fileProcessingService  : FileProcessingService|null
$isDefault  : bool
$isOnline  : bool|null
whether this storage is online or offline in this request
$processingFolder  : Folder|null
$processingFolders  : Folder[]|null
All processing folders of this storage used in any storage
$storageRecord  : array
The database record for this storage
$userPermissions  : array
The file permissions of the user (and their group) merged together and available as an array

Methods

__construct()  : mixed
Constructor for a storage object.
addFile()  : File
Moves a file from the local filesystem to this storage.
addFileAndFolderNameFilter()  : void
addFileMount()  : void
Adds a file mount as a "filter" for users to only work on a subset of a storage object
addUploadedFile()  : FileInterface
Adds an uploaded file into the Storage. Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::file_upload()
autoExtractMetadataEnabled()  : bool
Returns TRUE if auto extracting of metadata is enabled
checkFileActionPermission()  : bool
Checks if a file operation (= action) is allowed on a File/Folder/Storage (= subject).
checkFolderActionPermission()  : bool
Checks if a folder operation (= action) is allowed on a Folder.
checkUserActionPermission()  : bool
Checks if the ACL settings allow for a certain action (is a user allowed to read a file or copy a folder).
copyFile()  : File
Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_copy() copies a source file (from any location) in to the target folder, the latter has to be part of this storage
copyFolder()  : Folder
Copies a folder.
countFilesInFolder()  : int
countFoldersInFolder()  : int
createFile()  : ProcessedFile|File|null
Creates a new file
createFolder()  : Folder
Creates a new folder.
deleteFile()  : bool
Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::deleteFile()
deleteFolder()  : bool
Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::folder_delete()
getCapabilities()  : Capabilities
Returns the capabilities of this storage.
getConfiguration()  : array
getDefaultFolder()  : Folder
Returns the default folder where new files are stored if no other folder is given.
getDriverType()  : string
Gets the driver Type configured for this storage.
getEvaluatePermissions()  : bool
Gets whether the permissions to access or write into this storage should be checked or not.
getFile()  : ProcessedFile|File|null
Gets a file by identifier.
getFileAndFolderNameFilters()  : array
Returns the file and folder name filters used by this storage.
getFileByIdentifier()  : File|ProcessedFile|null
Gets a file object from storage by file identifier If the file is outside the process folder, it gets indexed and returned as file object afterward If the file is within processing folder, the file object will be directly returned
getFileContents()  : string
Get contents of a file object
getFileForLocalProcessing()  : string
Copies a file from the storage for local processing.
getFileIdentifiersInFolder()  : array
getFileInfo()  : array
Gets information about a file.
getFileInfoByIdentifier()  : array
Gets information about a file by its identifier.
getFileInFolder()  : File|ProcessedFile|null
Get file from folder
getFileMounts()  : array
Returns all file mounts that are registered with this storage.
getFilesInFolder()  : File[]
getFolder()  : Folder
getFolderIdentifierFromFileIdentifier()  : string
getFolderIdentifiersInFolder()  : array
getFolderInfo()  : array
Retrieves information about a folder
getFolderInFolder()  : Folder
Returns the folder object from the folder identifier within a given parent folder.
getFoldersInFolder()  : array<string|int, Folder>
getImportExportFilter()  : array<int, ImportExportFilter|string>
Returns a filter for files generated by EXT:impexp
getName()  : string
Returns the name of this storage.
getProcessingFolder()  : Folder
Getter function to return the folder where the files can be processed. Does not check for access rights here.
getProcessingFolders()  : Folder[]
Get all processing folders that live in this storage
getPublicUrl()  : string|null
Returns a publicly accessible URL for a file.
getResourceFactoryInstance()  : ResourceFactory
getRole()  : string
Gets the role of a folder.
getRootLevelFolder()  : Folder
Returns the folder on the root level of the storage or the first mount point of this storage for this user if $respectFileMounts is set.
getStorageRecord()  : array
getUid()  : int
Returns the UID of this storage.
getUploadedLocalFilePath()  : string
Resolves the actual local file path of a new uploaded file.
getUploadedTargetFileName()  : string
Resolves the actual sanitized file name to be used for persisting a new uploaded file.
hasChildren()  : bool
Tells whether there are children in this storage.
hasFile()  : bool
Returns TRUE if the specified file exists
hasFileInFolder()  : bool
Checks if the queried file in the given folder exists
hasFolder()  : bool
Returns TRUE if the specified folder exists.
hasFolderInFolder()  : bool
Checks if the given file exists in the given folder
hashFile()  : string
Creates a (cryptographic) hash for a file.
hashFileByIdentifier()  : string
Creates a (cryptographic) hash for a fileIdentifier.
hashFileIdentifier()  : string
Hashes a file identifier, taking the case sensitivity of the file system into account. This helps to mitigate problems with case-insensitive databases.
hasHierarchicalIdentifiers()  : bool
Returns TRUE if this storage stores folder structure in file identifiers.
isBrowsable()  : bool
Returns TRUE if this storage is browsable by a (backend) user of TYPO3.
isDefault()  : bool
isFallbackStorage()  : bool
Returns true if this storage is a virtual storage that provides access to all files in the project root.
isFileMountFolder()  : bool
isOnline()  : bool
Returns TRUE if this storage is browsable by a (backend) user of TYPO3.
isProcessingFolder()  : bool
Returns TRUE if folder that is in current storage is set as processing folder for one of the existing storages
isPublic()  : bool
Returns TRUE if this storage is publicly available. This is just a configuration option and does not mean that it really *is* public. OTOH a storage that is marked as not publicly available will trigger the file publishing mechanisms of TYPO3.
isWithinFileMountBoundaries()  : bool
Checks if the given subject is within one of the registered user file mounts. If not, working with the file is not permitted for the user.
isWithinFolder()  : bool
Checks if a resource (file or folder) is within the given folder
isWithinProcessingFolder()  : bool
Returns TRUE if the specified file is in a folder that is set a processing for a storage
isWritable()  : bool
Returns TRUE if this storage is writable. This is determined by the driver and the storage configuration; user permissions are not taken into account.
markAsPermanentlyOffline()  : void
Blows the "fuse" and marks the storage as offline.
markAsTemporaryOffline()  : void
Marks this storage as offline for the next 5 minutes.
moveFile()  : FileInterface
Moves a $file into a $targetFolder the target folder has to be part of this storage
moveFolder()  : Folder
Moves a folder. If you want to move a folder from this storage to another one, call this method on the target storage, otherwise you will get an exception.
processFile()  : ProcessedFile
Passes a file to the File Processing Services and returns the resulting ProcessedFile object.
renameFile()  : FileInterface
Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_rename()
renameFolder()  : Folder
Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::folder_move()
replaceAndRenameUploadedFile()  : FileInterface
Replaces an existing file with new contents and renames the file identifier.
replaceFile()  : FileInterface
Replaces a file with a local file (e.g. a freshly uploaded file)
resetFileAndFolderNameFiltersToDefault()  : void
Resets the file and folder name filters to the default values defined in the TYPO3 configuration.
sanitizeFileName()  : string
Clean up a fileName from not allowed characters
searchFiles()  : FileSearchResultInterface
Search for files in a storage based on given restrictions and a possibly given folder.
setConfiguration()  : void
setDefault()  : void
setDriver()  : $this
Sets the storage that belongs to this storage.
setEvaluatePermissions()  : void
Sets whether the permissions to access or write into this storage should be checked or not.
setFileAndFolderNameFilters()  : $this
setFileContents()  : int
Set contents of a file object.
setUserPermissions()  : void
Sets the user permissions of the storage.
streamFile()  : ResponseInterface
Returns a PSR-7 Response which can be used to stream the requested file
unsetFileAndFolderNameFilters()  : void
Unsets the file and folder name filters, thus making this storage return unfiltered filelists.
updateProcessedFile()  : ProcessedFile
Updates a processed file with a new file from the local filesystem.
usesCaseSensitiveIdentifiers()  : bool
Returns TRUE if the identifiers used by this storage are case-sensitive.
assertUploadedFileType()  : void
assureFileAddPermissions()  : void
Checks if a file/user has the permission to be written to a Folder/Storage.
assureFileCopyPermissions()  : void
Check if a file has the permission to be copied on a File/Folder/Storage, if not throw an exception
assureFileDeletePermissions()  : void
Assures delete permission for given file.
assureFileMovePermissions()  : void
Checks for permissions to move a file.
assureFileReadPermission()  : void
Assures read permission for given file.
assureFileRenamePermissions()  : void
Checks for permissions to rename a file.
assureFileReplacePermissions()  : void
Assure replace permission for given file.
assureFileUploadPermissions()  : void
Checks if a file has the permission to be uploaded to a Folder/Storage.
assureFileWritePermissions()  : void
Assures write permission for given file.
assureFolderCopyPermissions()  : void
Check if a file has the permission to be copied on a File/Folder/Storage, if not throw an exception.
assureFolderDeletePermission()  : void
Assures delete permission for given folder.
assureFolderMovePermissions()  : void
Check if a file has the permission to be copied on a File/Folder/Storage, if not throw an exception.
assureFolderReadPermission()  : void
Assures read permission for given folder.
assureResourceConsistency()  : void
checkFileExtensionPermission()  : bool
If the fileName is given, checks it against the TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed.
checkValidFileExtension()  : bool
Check file extension of an existing file against the current file deny pattern.
copyFolderBetweenStorages()  : mixed
Copies a folder between storages.
createFolderObject()  : Folder
Creates a folder to directly access (a part of) a storage.
getAllFileObjectsInFolder()  : array<string, File>
Returns an array with all file objects in a folder and its subfolders, with the file identifiers as keys.
getDriver()  : DriverInterface
Returns the driver object belonging to this storage.
getFileFactory()  : ResourceFactory
getFileIndexRepository()  : FileIndexRepository
getFileProcessingService()  : FileProcessingService
getIndexer()  : Indexer
getNamesForNestedProcessingFolder()  : string[]
Generates appropriate hashed sub-folder path for a given file identifier.
getNearestRecyclerFolder()  : Folder|null
Get the nearest Recycler folder for given file or folder
getNestedProcessingFolder()  : Folder
Getter function to return the file's corresponding hashed subfolder of the processed folder.
getProcessedFileRepository()  : ProcessedFileRepository
getPseudoStream()  : ResponseInterface
Wrap DriverInterface::dumpFileContents into a SelfEmittableStreamInterface
getUniqueName()  : string
Returns the destination path/fileName of a unique fileName/foldername in that path.
handleRenameFile()  : FileInterface
handleReplaceFile()  : FileInterface
hasCapability()  : bool
Returns TRUE if this storage has the given capability.
isAllowedActionOnMountFolder()  : bool
moveFolderBetweenStorages()  : mixed
Moves the given folder from a different storage to the target folder in this storage.

Constants

PROCESSING_FOLDER_LEVELS

Levels numbers used to generate hashed subfolders in the processing folder

public mixed PROCESSING_FOLDER_LEVELS = 2

Properties

$capabilities

The capabilities of this storage as defined in the storage record.

protected Capabilities $capabilities

$configuration

The configuration belonging to this storage (decoded from the configuration field).

protected array $configuration

$evaluatePermissions

Whether to check if file or folder is in user mounts and the action is allowed for a user Default is FALSE so that resources are accessible for front end rendering or admins.

protected bool $evaluatePermissions = false

$eventDispatcher

protected EventDispatcherInterface $eventDispatcher

$fileAndFolderNameFilters

The filters used for the files and folder names.

protected array $fileAndFolderNameFilters = []

$fileMounts

User file mounts, added as an array, and used as filters

protected array $fileMounts = []

$isDefault

protected bool $isDefault = false

$isOnline

whether this storage is online or offline in this request

protected bool|null $isOnline = null

$processingFolders

All processing folders of this storage used in any storage

protected Folder[]|null $processingFolders = null

$storageRecord

The database record for this storage

protected array $storageRecord

$userPermissions

The file permissions of the user (and their group) merged together and available as an array

protected array $userPermissions = []

Methods

__construct()

Constructor for a storage object.

public __construct(DriverInterface $driver, array $storageRecord[, EventDispatcherInterface|null $eventDispatcher = null ]) : mixed

Parameters

$driver : DriverInterface
$storageRecord : array

The storage record row from the database

$eventDispatcher : EventDispatcherInterface|null = null

addFile()

Moves a file from the local filesystem to this storage.

public addFile(string $localFilePath, Folder $targetFolder[, string $targetFileName = '' ][, DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ][, bool $removeOriginal = true ]) : File

Parameters

$localFilePath : string

The file on the server's hard disk to add

$targetFolder : Folder

The target folder where the file should be added

$targetFileName : string = ''

The name of the file to be added, If not set, the local file name is used

$conflictMode : DuplicationBehavior = DuplicationBehavior::RENAME
$removeOriginal : bool = true

if set the original file will be removed after successful operation

Tags

throws
InvalidArgumentException
throws
ExistingTargetFileNameException

Return values

File

addFileAndFolderNameFilter()

public addFileAndFolderNameFilter(callable $filter) : void

Parameters

$filter : callable

addFileMount()

Adds a file mount as a "filter" for users to only work on a subset of a storage object

public addFileMount(string $folderIdentifier[, array $additionalData = [] ]) : void

Parameters

$folderIdentifier : string
$additionalData : array = []

Tags

throws
FolderDoesNotExistException

addUploadedFile()

Adds an uploaded file into the Storage. Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::file_upload()

public addUploadedFile(array|UploadedFileInterface $uploadedFileData[, Folder|null $targetFolder = null ][, string|null $targetFileName = null ][, DuplicationBehavior $conflictMode = DuplicationBehavior::CANCEL ]) : FileInterface

Parameters

$uploadedFileData : array|UploadedFileInterface

Information about the uploaded file given by $_FILES['file1'] or a PSR-7 UploadedFileInterface object

$targetFolder : Folder|null = null

the target folder

$targetFileName : string|null = null

the file name to be written

$conflictMode : DuplicationBehavior = DuplicationBehavior::CANCEL

Return values

FileInterface

autoExtractMetadataEnabled()

Returns TRUE if auto extracting of metadata is enabled

public autoExtractMetadataEnabled() : bool

Return values

bool

checkFileActionPermission()

Checks if a file operation (= action) is allowed on a File/Folder/Storage (= subject).

public checkFileActionPermission(string $action, FileInterface $file) : bool

This method, by design, does not throw exceptions or do logging. Besides the usage from other methods in this class, it is also used by the Media module UI to check whether an action is allowed and whether action related UI elements should thus be shown (move icon, edit icon, etc.)

Parameters

$action : string

action, can be read, write, delete, editMeta

$file : FileInterface

Return values

bool

checkFolderActionPermission()

Checks if a folder operation (= action) is allowed on a Folder.

public checkFolderActionPermission(string $action[, FolderInterface|null $folder = null ]) : bool

This method, by design, does not throw exceptions or does logging. See the checkFileActionPermission() method above for the reasons.

Parameters

$action : string
$folder : FolderInterface|null = null

Return values

bool

checkUserActionPermission()

Checks if the ACL settings allow for a certain action (is a user allowed to read a file or copy a folder).

public checkUserActionPermission(string $action, string $type) : bool

Parameters

$action : string

(e.g. "read" or "write")

$type : string

either File or Folder

Return values

bool

copyFile()

Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_copy() copies a source file (from any location) in to the target folder, the latter has to be part of this storage

public copyFile(FileInterface $file, Folder $targetFolder[, string|null $targetFileName = null ][, DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : File

Parameters

$file : FileInterface
$targetFolder : Folder
$targetFileName : string|null = null

an optional destination fileName

$conflictMode : DuplicationBehavior = DuplicationBehavior::RENAME

Tags

throws
Exception|AbstractFileOperationException
throws
ExistingTargetFileNameException

Return values

File

copyFolder()

Copies a folder.

public copyFolder(FolderInterface $folderToCopy, FolderInterface $targetParentFolder[, string|null $newFolderName = null ][, DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : Folder

Parameters

$folderToCopy : FolderInterface

The folder to copy

$targetParentFolder : FolderInterface

The target folder

$newFolderName : string|null = null
$conflictMode : DuplicationBehavior = DuplicationBehavior::RENAME

Tags

throws
InvalidTargetFolderException

Return values

Folder —

The new (copied) folder object

createFile()

Creates a new file

public createFile(string $fileName, Folder $targetFolderObject) : ProcessedFile|File|null

previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_newfile()

Parameters

$fileName : string

The name of the file to be created

$targetFolderObject : Folder

The target folder where the file should be created

Tags

throws
IllegalFileExtensionException
throws
InsufficientFolderWritePermissionsException

Return values

ProcessedFile|File|null

createFolder()

Creates a new folder.

public createFolder(string $folderName[, Folder|null $parentFolder = null ]) : Folder

previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_newfolder()

Parameters

$folderName : string

The new folder name

$parentFolder : Folder|null = null

(optional) the parent folder to create the new folder inside of. If not given, the root folder is used

Tags

throws
ExistingTargetFolderException
throws
InsufficientFolderAccessPermissionsException
throws
InsufficientFolderWritePermissionsException
throws
Exception

Return values

Folder

deleteFolder()

Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::folder_delete()

public deleteFolder(Folder $folderObject[, bool $deleteRecursively = false ]) : bool

Parameters

$folderObject : Folder
$deleteRecursively : bool = false

Tags

throws
RuntimeException
throws
InsufficientFolderAccessPermissionsException
throws
InsufficientUserPermissionsException
throws
FileOperationErrorException

Return values

bool

getConfiguration()

public getConfiguration() : array

Return values

array

getDefaultFolder()

Returns the default folder where new files are stored if no other folder is given.

public getDefaultFolder() : Folder

Return values

Folder

getDriverType()

Gets the driver Type configured for this storage.

public getDriverType() : string

Return values

string

getEvaluatePermissions()

Gets whether the permissions to access or write into this storage should be checked or not.

public getEvaluatePermissions() : bool

Return values

bool

getFileAndFolderNameFilters()

Returns the file and folder name filters used by this storage.

public getFileAndFolderNameFilters() : array

Return values

array

getFileByIdentifier()

Gets a file object from storage by file identifier If the file is outside the process folder, it gets indexed and returned as file object afterward If the file is within processing folder, the file object will be directly returned

public getFileByIdentifier(string $fileIdentifier) : File|ProcessedFile|null

Parameters

$fileIdentifier : string

Return values

File|ProcessedFile|null —

Returns ProcessedFile|null only if a processed file is requested, always File otherwise

getFileForLocalProcessing()

Copies a file from the storage for local processing.

public getFileForLocalProcessing(FileInterface $fileObject[, bool $writable = true ]) : string

Parameters

$fileObject : FileInterface
$writable : bool = true

Return values

string —

Path to local file (either original or copied to some temporary local location)

getFileIdentifiersInFolder()

public getFileIdentifiersInFolder(string $folderIdentifier[, bool $useFilters = true ][, bool $recursive = false ]) : array

Parameters

$folderIdentifier : string
$useFilters : bool = true
$recursive : bool = false

Return values

array

getFileInfoByIdentifier()

Gets information about a file by its identifier.

public getFileInfoByIdentifier(string $identifier[, array $propertiesToExtract = [] ]) : array

Parameters

$identifier : string
$propertiesToExtract : array = []

Return values

array

getFileMounts()

Returns all file mounts that are registered with this storage.

public getFileMounts() : array

Return values

array

getFilesInFolder()

public getFilesInFolder(Folder $folder[, int $start = 0 ][, int $maxNumberOfItems = 0 ][, bool $useFilters = true ][, bool $recursive = false ][, string $sort = '' ][, bool $sortRev = false ]) : File[]

Parameters

$folder : Folder
$start : int = 0
$maxNumberOfItems : int = 0
$useFilters : bool = true
$recursive : bool = false
$sort : string = ''

Property name used to sort the items. Among them may be: '' (empty, no sorting), name, fileext, size, tstamp and rw. If a driver does not support the given property, it should fall back to "name".

$sortRev : bool = false

TRUE to indicate reverse sorting (last to first)

Tags

throws
InsufficientFolderAccessPermissionsException

Return values

File[]

getFolderIdentifierFromFileIdentifier()

public getFolderIdentifierFromFileIdentifier(string $fileIdentifier) : string

Parameters

$fileIdentifier : string

Return values

string

getFolderIdentifiersInFolder()

public getFolderIdentifiersInFolder(string $folderIdentifier[, bool $useFilters = true ][, bool $recursive = false ]) : array

Parameters

$folderIdentifier : string
$useFilters : bool = true
$recursive : bool = false

Return values

array

getFolderInfo()

Retrieves information about a folder

public getFolderInfo(Folder $folder) : array

Parameters

$folder : Folder

Return values

array

getFolderInFolder()

Returns the folder object from the folder identifier within a given parent folder.

public getFolderInFolder(string $folderName, Folder $parentFolder[, bool $returnInaccessibleFolderObject = false ]) : Folder

Parameters

$folderName : string

The name of the target folder

$parentFolder : Folder
$returnInaccessibleFolderObject : bool = false

Tags

throws
Exception
throws
InsufficientFolderAccessPermissionsException

Return values

Folder

getFoldersInFolder()

public getFoldersInFolder(Folder $folder[, int $start = 0 ][, int $maxNumberOfItems = 0 ][, bool $useFilters = true ][, bool $recursive = false ][, string $sort = '' ][, bool $sortRev = false ]) : array<string|int, Folder>

Parameters

$folder : Folder
$start : int = 0
$maxNumberOfItems : int = 0
$useFilters : bool = true
$recursive : bool = false
$sort : string = ''

Property name used to sort the items. Among them may be: '' (empty, no sorting), name, fileext, size, tstamp and rw. If a driver does not support the given property, it should fall back to "name".

$sortRev : bool = false

TRUE to indicate reverse sorting (last to first)

Return values

array<string|int, Folder>

getName()

Returns the name of this storage.

public getName() : string

Return values

string

getProcessingFolder()

Getter function to return the folder where the files can be processed. Does not check for access rights here.

public getProcessingFolder([File|null $file = null ]) : Folder

Parameters

$file : File|null = null

Specific file you want to have the processing folder for

Return values

Folder

getProcessingFolders()

Get all processing folders that live in this storage

public getProcessingFolders() : Folder[]

Return values

Folder[]

getPublicUrl()

Returns a publicly accessible URL for a file.

public getPublicUrl(ResourceInterface $resourceObject) : 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

$resourceObject : ResourceInterface

The file or folder object

Return values

string|null —

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

getRole()

Gets the role of a folder.

public getRole(FolderInterface $folder) : string

Parameters

$folder : FolderInterface

Folder object to get the role from

Return values

string —

The role the folder has

getRootLevelFolder()

Returns the folder on the root level of the storage or the first mount point of this storage for this user if $respectFileMounts is set.

public getRootLevelFolder([bool $respectFileMounts = true ]) : Folder

Parameters

$respectFileMounts : bool = true

Tags

todo:

this is a bad method design, because the calling code can never fetch all file mounts nor traverse them.

Return values

Folder

getStorageRecord()

public getStorageRecord() : array

Return values

array

getUid()

Returns the UID of this storage.

public getUid() : int

Return values

int

getUploadedLocalFilePath()

Resolves the actual local file path of a new uploaded file.

public getUploadedLocalFilePath(array|UploadedFileInterface $uploadedFileData) : string

Parameters

$uploadedFileData : array|UploadedFileInterface

Return values

string

getUploadedTargetFileName()

Resolves the actual sanitized file name to be used for persisting a new uploaded file.

public getUploadedTargetFileName(array|UploadedFileInterface $uploadedFileData[, string|null $targetFileName = null ]) : string

Parameters

$uploadedFileData : array|UploadedFileInterface
$targetFileName : string|null = null

Return values

string

hasChildren()

Tells whether there are children in this storage.

public hasChildren() : bool

Return values

bool

hasFile()

Returns TRUE if the specified file exists

public hasFile(string $identifier) : bool

Parameters

$identifier : string

Return values

bool

hasFileInFolder()

Checks if the queried file in the given folder exists

public hasFileInFolder(string $fileName, Folder $folder) : bool

Parameters

$fileName : string
$folder : Folder

Return values

bool

hasFolder()

Returns TRUE if the specified folder exists.

public hasFolder(string $identifier) : bool

Parameters

$identifier : string

Return values

bool

hasFolderInFolder()

Checks if the given file exists in the given folder

public hasFolderInFolder(string $folderName, Folder $folder) : bool

Parameters

$folderName : string
$folder : Folder

Return values

bool

hashFile()

Creates a (cryptographic) hash for a file.

public hashFile(FileInterface $fileObject, string $hashAlgorithm) : string

Parameters

$fileObject : FileInterface
$hashAlgorithm : string

Return values

string

hashFileByIdentifier()

Creates a (cryptographic) hash for a fileIdentifier.

public hashFileByIdentifier(string $fileIdentifier, string $hashAlgorithm) : string

Parameters

$fileIdentifier : string
$hashAlgorithm : string

Tags

throws
InvalidHashException

Return values

string

hashFileIdentifier()

Hashes a file identifier, taking the case sensitivity of the file system into account. This helps to mitigate problems with case-insensitive databases.

public hashFileIdentifier(FileInterface|string $file) : string

Parameters

$file : FileInterface|string

Return values

string

hasHierarchicalIdentifiers()

Returns TRUE if this storage stores folder structure in file identifiers.

public hasHierarchicalIdentifiers() : bool

Return values

bool

isBrowsable()

Returns TRUE if this storage is browsable by a (backend) user of TYPO3.

public isBrowsable() : bool

Return values

bool

isDefault()

public isDefault() : bool

Return values

bool

isFallbackStorage()

Returns true if this storage is a virtual storage that provides access to all files in the project root.

public isFallbackStorage() : bool

Return values

bool

isFileMountFolder()

public isFileMountFolder(Folder $folder) : bool

Parameters

$folder : Folder

Return values

bool

isOnline()

Returns TRUE if this storage is browsable by a (backend) user of TYPO3.

public isOnline() : bool

Return values

bool

isProcessingFolder()

Returns TRUE if folder that is in current storage is set as processing folder for one of the existing storages

public isProcessingFolder(Folder $folder) : bool

Parameters

$folder : Folder

Return values

bool

isPublic()

Returns TRUE if this storage is publicly available. This is just a configuration option and does not mean that it really *is* public. OTOH a storage that is marked as not publicly available will trigger the file publishing mechanisms of TYPO3.

public isPublic() : bool

Return values

bool

isWithinFileMountBoundaries()

Checks if the given subject is within one of the registered user file mounts. If not, working with the file is not permitted for the user.

public isWithinFileMountBoundaries(ResourceInterface $subject[, bool $checkWriteAccess = false ]) : bool

Parameters

$subject : ResourceInterface

file or folder

$checkWriteAccess : bool = false

If true, it is not only checked if the subject is within the file mount but also whether it isn't a read only file mount

Return values

bool

isWithinProcessingFolder()

Returns TRUE if the specified file is in a folder that is set a processing for a storage

public isWithinProcessingFolder(string $identifier) : bool

Parameters

$identifier : string

Return values

bool

isWritable()

Returns TRUE if this storage is writable. This is determined by the driver and the storage configuration; user permissions are not taken into account.

public isWritable() : bool

Return values

bool

markAsPermanentlyOffline()

Blows the "fuse" and marks the storage as offline.

public markAsPermanentlyOffline() : void

Can only be modified by an admin.

Typically, this is only done if the configuration is wrong.

markAsTemporaryOffline()

Marks this storage as offline for the next 5 minutes.

public markAsTemporaryOffline() : void

Non-permanent: This typically happens for remote storages that are "flaky" and not available all the time.

moveFile()

Moves a $file into a $targetFolder the target folder has to be part of this storage

public moveFile(FileInterface $file, Folder $targetFolder[, string|null $targetFileName = null ][, DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : FileInterface

previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_move()

Parameters

$file : FileInterface
$targetFolder : Folder
$targetFileName : string|null = null

an optional destination fileName

$conflictMode : DuplicationBehavior = DuplicationBehavior::RENAME

Tags

throws
ExistingTargetFileNameException
throws
RuntimeException

Return values

FileInterface

moveFolder()

Moves a folder. If you want to move a folder from this storage to another one, call this method on the target storage, otherwise you will get an exception.

public moveFolder(Folder $folderToMove, Folder $targetParentFolder[, string|null $newFolderName = null ][, DuplicationBehavior $conflictMode = DuplicationBehavior::RENAME ]) : Folder

Parameters

$folderToMove : Folder

The folder to move.

$targetParentFolder : Folder

The target parent folder

$newFolderName : string|null = null
$conflictMode : DuplicationBehavior = DuplicationBehavior::RENAME

Tags

throws
Exception|Exception
throws
InvalidArgumentException
throws
InvalidTargetFolderException

Return values

Folder

replaceAndRenameUploadedFile()

Replaces an existing file with new contents and renames the file identifier.

public replaceAndRenameUploadedFile(array|UploadedFileInterface $sourceFile, FileInterface $targetFile[, string|null $targetFileName = null ]) : FileInterface

Parameters

$sourceFile : array|UploadedFileInterface
$targetFile : FileInterface
$targetFileName : string|null = null

Return values

FileInterface

resetFileAndFolderNameFiltersToDefault()

Resets the file and folder name filters to the default values defined in the TYPO3 configuration.

public resetFileAndFolderNameFiltersToDefault() : void

sanitizeFileName()

Clean up a fileName from not allowed characters

public sanitizeFileName(string $fileName[, Folder|null $targetFolder = null ]) : string

Parameters

$fileName : string

The name of the file to be sanitized

$targetFolder : Folder|null = null

The target folder where the file is located or should be added

Return values

string

setConfiguration()

public setConfiguration(array $configuration) : void

Parameters

$configuration : array

setDefault()

public setDefault(bool $isDefault) : void

Parameters

$isDefault : bool

setEvaluatePermissions()

Sets whether the permissions to access or write into this storage should be checked or not.

public setEvaluatePermissions(bool $evaluatePermissions) : void

Parameters

$evaluatePermissions : bool

setFileAndFolderNameFilters()

public setFileAndFolderNameFilters(array $filters) : $this

Parameters

$filters : array

Return values

$this

setUserPermissions()

Sets the user permissions of the storage.

public setUserPermissions(array $userPermissions) : void

Parameters

$userPermissions : array

streamFile()

Returns a PSR-7 Response which can be used to stream the requested file

public streamFile(FileInterface $file[, bool $asDownload = false ][, string|null $alternativeFilename = null ][, string|null $overrideMimeType = null ]) : ResponseInterface

Parameters

$file : FileInterface
$asDownload : bool = false

If set Content-Disposition attachment is sent, inline otherwise

$alternativeFilename : string|null = null

the filename for the download (if $asDownload is set)

$overrideMimeType : string|null = null

If set this will be used as Content-Type header instead of the automatically detected mime type.

Return values

ResponseInterface

unsetFileAndFolderNameFilters()

Unsets the file and folder name filters, thus making this storage return unfiltered filelists.

public unsetFileAndFolderNameFilters() : void

updateProcessedFile()

Updates a processed file with a new file from the local filesystem.

public updateProcessedFile(string $localFilePath, ProcessedFile $processedFile[, Folder|null $processingFolder = null ]) : ProcessedFile

Parameters

$localFilePath : string
$processedFile : ProcessedFile
$processingFolder : Folder|null = null

Tags

throws
InvalidArgumentException

Return values

ProcessedFile

usesCaseSensitiveIdentifiers()

Returns TRUE if the identifiers used by this storage are case-sensitive.

public usesCaseSensitiveIdentifiers() : bool

Return values

bool

assertUploadedFileType()

protected assertUploadedFileType(array|UploadedFileInterface $uploadedFileData) : void

Parameters

$uploadedFileData : array|UploadedFileInterface

Tags

throws
InvalidArgumentException

assureFileAddPermissions()

Checks if a file/user has the permission to be written to a Folder/Storage.

protected assureFileAddPermissions(FolderInterface $targetFolder, string $targetFileName) : void

If not, throws an exception.

Parameters

$targetFolder : FolderInterface

The target folder where the file should be written

$targetFileName : string

The file name which should be written into the storage

Tags

throws
InsufficientFolderWritePermissionsException
throws
IllegalFileExtensionException
throws
InsufficientUserPermissionsException

assureFileCopyPermissions()

Check if a file has the permission to be copied on a File/Folder/Storage, if not throw an exception

protected assureFileCopyPermissions(FileInterface $file, FolderInterface $targetFolder, string $targetFileName) : void

Parameters

$file : FileInterface
$targetFolder : FolderInterface
$targetFileName : string

Tags

throws
Exception
throws
InsufficientFolderWritePermissionsException
throws
IllegalFileExtensionException
throws
InsufficientFileReadPermissionsException
throws
InsufficientUserPermissionsException

assureFileUploadPermissions()

Checks if a file has the permission to be uploaded to a Folder/Storage.

protected assureFileUploadPermissions(string|array|UploadedFileInterface $uploadedFileData, FolderInterface $targetFolder, string $targetFileName, int $uploadedFileSize) : void

If not, throws an exception.

Parameters

$uploadedFileData : string|array|UploadedFileInterface
$targetFolder : FolderInterface

The target folder where the file should be uploaded

$targetFileName : string

the destination file name $_FILES['file1']['name']

$uploadedFileSize : int

Tags

throws
InsufficientFolderWritePermissionsException
throws
UploadException
throws
IllegalFileExtensionException
throws
UploadSizeException
throws
InsufficientUserPermissionsException

assureFolderCopyPermissions()

Check if a file has the permission to be copied on a File/Folder/Storage, if not throw an exception.

protected assureFolderCopyPermissions(FolderInterface $folderToCopy, FolderInterface $targetParentFolder) : void

Parameters

$folderToCopy : FolderInterface
$targetParentFolder : FolderInterface

Tags

throws
Exception
throws
InsufficientFolderWritePermissionsException
throws
IllegalFileExtensionException
throws
InsufficientFileReadPermissionsException
throws
InsufficientUserPermissionsException
throws
RuntimeException

assureFolderDeletePermission()

Assures delete permission for given folder.

protected assureFolderDeletePermission(FolderInterface $folder, bool $checkDeleteRecursively) : void

Parameters

$folder : FolderInterface

If a folder is given, mountpoints are checked. If not only user folder delete permissions are checked.

$checkDeleteRecursively : bool

Tags

throws
InsufficientFolderAccessPermissionsException
throws
InsufficientFolderWritePermissionsException
throws
InsufficientUserPermissionsException

checkFileExtensionPermission()

If the fileName is given, checks it against the TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed.

protected checkFileExtensionPermission(string $fileName) : bool

Parameters

$fileName : string

full filename

Return values

bool —

TRUE if extension/filename is allowed

checkValidFileExtension()

Check file extension of an existing file against the current file deny pattern.

protected checkValidFileExtension(FileInterface $file) : bool

Parameters

$file : FileInterface

Return values

bool

createFolderObject()

Creates a folder to directly access (a part of) a storage.

protected createFolderObject(string $identifier, string $name) : Folder

Parameters

$identifier : string

The path to the folder. Might also be a simple unique string, depending on the storage driver.

$name : string

The name of the folder (e.g. the folder name)

Return values

Folder

getAllFileObjectsInFolder()

Returns an array with all file objects in a folder and its subfolders, with the file identifiers as keys.

protected getAllFileObjectsInFolder(Folder $folder) : array<string, File>

Parameters

$folder : Folder

Return values

array<string, File>

getDriver()

Returns the driver object belonging to this storage.

protected getDriver() : DriverInterface

Note: This is a non-public method on purpose, because the outside world should never know if this is a local or remote storage.

Return values

DriverInterface

getNamesForNestedProcessingFolder()

Generates appropriate hashed sub-folder path for a given file identifier.

protected getNamesForNestedProcessingFolder(string $fileIdentifier, int $levels) : string[]

Parameters

$fileIdentifier : string
$levels : int

Return values

string[]

getNearestRecyclerFolder()

Get the nearest Recycler folder for given file or folder

protected getNearestRecyclerFolder(ResourceInterface $resource) : Folder|null

Return null if:

  • There is no folder with ROLE_RECYCLER in the rootline of the given Resource
  • Resource is a ProcessedFile (we don't know the concept of recycler folders for processedFiles)
  • Resource is located in a folder with ROLE_RECYCLER

Parameters

$resource : ResourceInterface

Return values

Folder|null

getPseudoStream()

Wrap DriverInterface::dumpFileContents into a SelfEmittableStreamInterface

protected getPseudoStream(FileInterface $file[, bool $asDownload = false ][, string|null $alternativeFilename = null ][, string|null $overrideMimeType = null ]) : ResponseInterface

Parameters

$file : FileInterface
$asDownload : bool = false

If set Content-Disposition attachment is sent, inline otherwise

$alternativeFilename : string|null = null

the filename for the download (if $asDownload is set)

$overrideMimeType : string|null = null

If set this will be used as Content-Type header instead of the automatically detected mime type.

Return values

ResponseInterface

getUniqueName()

Returns the destination path/fileName of a unique fileName/foldername in that path.

protected getUniqueName(FolderInterface $folder, string $theFile[, bool $dontCheckForUnique = false ]) : string

If $theFile exists in $theDest (directory) the file have numbers appended up to $this->maxNumber. Hereafter a unique string will be appended. This function is used by fx. DataHandler when files are attached to records and needs to be uniquely named in the uploads/* folders

Parameters

$folder : FolderInterface
$theFile : string

The input fileName to check

$dontCheckForUnique : bool = false

If set the fileName is returned with the path prepended without checking whether it already existed!

Tags

throws
RuntimeException
see
BasicFileUtility::getUniqueName()

Return values

string —

A unique fileName inside $folder, based on $theFile.

hasCapability()

Returns TRUE if this storage has the given capability.

protected hasCapability(Capabilities::CAPABILITY_* $capability) : bool

Parameters

$capability : Capabilities::CAPABILITY_*

Return values

bool

moveFolderBetweenStorages()

Moves the given folder from a different storage to the target folder in this storage.

protected moveFolderBetweenStorages(Folder $folderToMove, Folder $targetParentFolder, string $newFolderName) : mixed

Parameters

$folderToMove : Folder
$targetParentFolder : Folder
$newFolderName : string

Tags

throws
NotImplementedMethodException
On this page