Attention

TYPO3 v9 has reached its end-of-life September 30th, 2021 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.

You can order Extended Long Term Support (ELTS) here: TYPO3 ELTS.

File Functions Basics

File operations in the TCE are handled by the class \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility which extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility. The instructions for file manipulation are passed to this class as a multidimensional array.

Files Array

Syntax:

$file[ command ][ index ][ key ] = value

Description of keywords in syntax:

Key

Data type

Description

command

string (command keyword)

The command type you want to execute.

See table below for command keywords, keys and values

index

integer

Integer index in the array which separates multiple commands of the same type.

key

string

Depending on the command type. The keys will carry the information needed to perform the action. Typically a "target" key is used to point to the target directory or file while a "data" key carries the data.

See table below for command keywords, keys and values

value

string

The value for the command

See table below for command keywords, keys and values

Command Keywords and Values

Command

Keys

Value

delete

"data"

"data" = Absolute path to the file/folder to delete

copy

"data"

"target"

"altName"

"data" = Absolute path to the file/folder to copy

"target" = Absolute path to the folder to copy to (destination)

"altName" = (boolean): If set, a new filename is made by appending numbers/unique-string in case the target already exists.

move

"data"

"target"

"altName"

(Exactly like copy, just replace the word "copy" with "move")

rename

"data"

"target"

"data" = New name, max 30 characters alphanumeric

"target" = Absolute path to the target file/folder

newfolder

"data"

"target"

"data" = Folder name, max 30 characters alphanumeric

"target" = Absolute path to the folder where to create it

newfile

"data"

"target"

"data" = New filename

"target" = Absolute path to the folder where to create it

editfile

"data"

"target"

"data" = The new content

"target" = Absolute path to the target file

upload

"data"

"target"

upload_$id

"data" = ID-number (points to the global var that holds the filename- ref ($_FILES["upload_" . $id]["name"]).

"target" = Absolute path to the target folder (destination)

upload_$id = File reference. $id must equal value of file[upload][...][data]!

See \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_upload().

unzip

"data"

"target"

"data" = Absolute path to the zip-file. (file extension must be "zip")

"target" = The absolute path to the target folder (destination) (if not set, default is the same as the zip-file)

It is unlikely that you will need to use this internally in your scripts like you will need \TYPO3\CMS\Core\DataHandling\DataHandler. It is fairly uncommon to need the file manipulations in own scripts unless you make a special application. Therefore the most typical usage of this API is from \TYPO3\CMS\Backend\Controller\File\FileController and the Core scripts that are activated by the File > List module.

However, if needed, this is an example of how to initialize usage. It is taken from ImportExportController.php:

1// Initializing:
2$this->fileProcessor = GeneralUtility::makeInstance(ExtendedFileUtility::class);
3$this->fileProcessor->setActionPermissions();
4
5$this->fileProcessor->start($this->file);
6$this->fileProcessor->processData();

Explanation: Line 2 creates an instance of the class. Then the file operation permissions are loaded from the user object in line 3. Finally, the file command array is loaded in line 5 and internally additional configuration takes place according to $GLOBALS['TYPO3_CONF_VARS']!. In line 6 the command map is executed.