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 ( "target" = Absolute path to the target folder (destination) upload_$id = File reference. $id must equal value of
See |
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 TYPO3CMSBackendControllerFileFileController
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 2 3 4 5 6 | // Initializing:
$this->fileProcessor = GeneralUtility::makeInstance(ExtendedFileUtility::class);
$this->fileProcessor->setActionPermissions();
$this->fileProcessor->start($this->file);
$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.