File 

New in version 13.0

The TCA type file creates a field where files can be attached to the record.

The according database field is generated automatically.

Table of contents:

Example 

A conference has one logo and any number of impressions:

EXT:my_extension/Configuration/TCA/Overrides/155-tx_myextension_conference-media.php
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
  'logo' => [
    'label' => 'my_extension.db:conference.logo',
    'config' => [
      'type' => 'file',
      'maxitems' => 1,
      'allowed' => 'common-image-types',
      'relationship' => 'manyToOne',
    ],
  ],
  'impressions' => [
    'label' => 'my_extension.db:conference.impressions',
    'config' => [
      'type' => 'file',
      'allowed' => 'common-image-types',
      'overrideChildTca' => [
        'columns' => [
          'crop' => [
            'config' => [
              'cropVariants' => [
                'desktop' => [
                  'title' => 'my_extension.db:conference.impressions.desktop',
                  'allowedAspectRatios' => [
                    '16:9' => [
                      'title' => 'core.wizards:imwizard.ratio.16_9',
                      'value' => 16 / 9,
                    ],
                    'NaN' => [
                      'title' => 'core.wizards:imwizard.ratio.free',
                      'value' => 0.0,
                    ],
                  ],
                ],
                'mobile' => [
                  'title' => 'my_extension.db:conference.impressions.mobile',
                  'allowedAspectRatios' => [
                    '4:3' => [
                      'title' => 'core.wizards:imwizard.ratio.4_3',
                      'value' => 4 / 3,
                    ],
                  ],
                  // Initially the middle of the image, without the edges
                  'cropArea' => [
                    'x' => 0.1,
                    'y' => 0.1,
                    'width' => 0.8,
                    'height' => 0.8,
                  ],
                ],
              ],
              // A translated image keeps the crop of the default language,
              // unless the editors crop it anew
              'behaviour' => [
                'allowLanguageSynchronization' => true,
              ],
            ],
          ],
        ],
      ],
    ],
  ],
]);
$GLOBALS['TCA']['tx_myextension_conference']['palettes']['media'] = [
  'showitem' => 'logo, impressions',
];
ExtensionManagementUtility::addToAllTCAtypes(
  'tx_myextension_conference',
  '--palette--;;media',
  '',
  'before:--div--;core.form.tabs:categories',
);
Copied!

Properties of the TCA column type file 

Name Type Scope
string / array Display / Proc.
array Display
boolean Proc.
boolean Proc.
boolean Proc.
array Display / Proc.
array Display
array
array
array
integer > 0 Display / Proc.
integer > 0 Display
array Display
boolean Display
string Proc.
allowed
Type
string / array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed']
Scope
Display / Proc.

One or more (comma-separated) of the following reserved strings:

common-image-types
Gets replaced with the value from $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] .
common-text-types
Gets replaced with the value from $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'] .
common-media-types
Gets replaced with the value from $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'] .

Additionally, specific allowed file extensions can be added (comma separated), for example 'common-image-types, common-text-types, gz, zip .

You can also use the array notation of allowed file extensions, for example ['jpg','png','svg'] or ['common-image-types', 'gz', 'zip'] .

New in version 13.1.0

Due to a bug, the array notation only properly works since TYPO3 13.1.0 and v12.4.1 and upwards. Use the string notation for earlier versions instead.

appearance
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['appearance']
Scope
Display

Has information about the appearance of child-records, namely:

collapseAll (boolean)
Show all child-records collapsed (if false, all are expanded)
expandSingle (boolean)
Show only one child-record expanded each time. If a collapsed record is clicked, the currently open one collapses and the clicked one expands.
createNewRelationLinkTitle (plain text label or label reference)
Overrides the link text and title of the "Create new relation" button with a localized string. Only useful, if the element browser is enabled.
addMediaLinkTitle (plain text label or label reference)
Overrides the link text and title of the "Add media by URL" button with a localized string. Only useful, if the element browser is enabled.
uploadFilesLinkTitle (plain text label or label reference)
Overrides the link text and title of the "Select & upload files" button with a localized string. Only useful, if the element browser is enabled.
useSortable (boolean)
Activate drag & drop.
showPossibleLocalizationRecords (boolean)
Show unlocalized files which are in the original language, but not yet localized.
showAllLocalizationLink (boolean)
Defines whether to show the "localize all records" link to fetch untranslated records from the original language.
showSynchronizationLink (boolean)
Defines whether to show a "synchronize" link to update to a 1:1 translation with the original language.
enabledControls (array)
Associative array with the keys 'info', 'new', 'dragdrop', 'sort', 'hide', 'delete', 'localize'. If the accordant values are set to a boolean value (true or false), the control is shown or hidden in the header of each record.
headerThumbnail (array)

Defines whether a thumbnail should be rendered in the inline element's header. This is used by the file abstraction layer to render a preview of the related image. Can contain image processing instructions like width and height.

field (required)
The table column name, which contains the uid of the image reference. Usually this is uid_local.
width
The width of the thumbnail.
height
The height of the thumbnail.
fileUploadAllowed (boolean)

Defines whether the button "Select & upload file" should be rendered. This can be used for file fields to directly upload files and create a reference to the file. The button is limited to file fields using File Abstraction Layer. It will only appear to backend users which have write access to the user upload folder. By default this folder is fileadmin/user_upload but it can be changed in User TSconfig using options.defaultUploadFolder . See the TSconfig reference.

The button is shown by default unless this option is set to false .

fileByUrlAllowed (boolean)
Defines whether the button "Add media by URL" should be rendered. This button is used to include media URLs from, for example, Vimeo or YouTube.
elementBrowserEnabled (boolean)
Hides or displays the element browser button in inline records

This property can also be overridden by page TSconfig.

behaviour
allowLanguageSynchronization
Type
boolean
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['behaviour']['allowLanguageSynchronization']
Scope
Proc.

Allows an editor to select in a localized record whether the value is copied over from default or source language record, or if the field has an own value in the localization. If set to true and if the table supports localization and if a localized record is edited, this setting enables FieldWizard LocalizationStateSelector: Two or three radio buttons shown below the field input. The state of this is stored in a json encoded array in the database table called l10n_state. It tells the DataHandler which fields of the localization records should be kept in sync if the underlying default or source record changes.

This property can also be overridden by page TSconfig.

disableMovingChildrenWithParent
Type
boolean
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['behaviour']['disableMovingChildrenWithParent']
Scope
Proc.

Default false. Disables that child records get moved along with their parent records. Usually if in a parent-child relation a parent record is moved to a different page (eg. via cut+paste from clipboard), the children are relocated along with the parent. This flag disables the child move.

This property can also be overridden by page TSconfig.

enableCascadingDelete
Type
boolean
Default
true
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['behaviour']['enableCascadingDelete']
Scope
Proc.

Usually when the parent record is deleted all attached sys_file_references are deleted. This default behaviour can be disabled here.

This property can also be overridden by page TSconfig.

disallowed
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['disallowed']
Scope
Display / Proc.

An array of file extensions that are not allowed even though they are listed in the property allowed, for example ['doc','docx'] .

fieldInformation
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldInformation']
Scope
Display

Show information between an element label and the main element input area. Configuration works identical to the "fieldWizard" property, no default configuration in the core exists (yet). In contrast to "fieldWizard", HTML returned by fieldInformation is limited, see FormEngine docs for more details.

fieldWizard
defaultLanguageDifferences
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['defaultLanguageDifferences']

For details see defaultLanguageDifferences.

localizationStateSelector
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['localizationStateSelector']

For details see localizationStateSelector.

otherLanguageContent
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['otherLanguageContent']

For details see otherLanguageContent.

maxitems
Type
integer > 0
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['maxitems']
Scope
Display / Proc.

Maximum number of files that can be attached. Defaults to a high value. JavaScript record validation prevents the record from being saved if the limit is not satisfied.

This property can also be overridden by page TSconfig.

minitems
Type
integer > 0
Default
0
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['minitems']
Scope
Display
Types
group, inline

Minimum number of attached files. JavaScript record validation prevents the record from being saved if the limit is not satisfied.

This property can also be overridden by page TSconfig.

Example, a sponsor has exactly one logo:

EXT:my_extension/Configuration/TCA/Overrides/710-tx_myextension_sponsor-logo.php
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tx_myextension_sponsor', [
  'logo' => [
    'label' => 'my_extension.db:sponsor.logo',
    'config' => [
      'type' => 'file',
      // Every sponsor has exactly one logo
      'minitems' => 1,
      'maxitems' => 1,
      'allowed' => 'common-image-types',
    ],
  ],
]);
ExtensionManagementUtility::addToAllTCAtypes(
  'tx_myextension_sponsor',
  'logo',
  '',
  'after:tier',
);
Copied!
overrideChildTca
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['overrideChildTca']
Scope
Display

Override the TCA of the sys_file_reference records representing the files attached to this record.

readOnly
Type
boolean
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['readOnly']
Scope
Display

The files attached to this record are displayed but cannot be changed in the backend form.

This property can also be overridden by page TSconfig.

relationship
Type
string
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['relationship']
Scope
Proc.
Added
13.3

Defines whether the field holds one file reference or several. This decides which value a Record object provides for this field, for example in a Fluid template.

oneToOne, manyToOne
The field provides a single FileReference object, or null if no file is attached. maxitems is set to 1 automatically, overriding any other value.
oneToMany
The field provides a LazyFileReferenceCollection of FileReference objects.

If relationship is not set, the field also provides a collection. Any other value, including manyToMany, throws an exception.

maxitems does not change the result the other way round: a field without relationship still provides a collection, even if maxitems is 1.

In the following example, a conference has one logo:

EXT:my_extension/Configuration/TCA/Overrides/155-tx_myextension_conference-media.php
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
  'logo' => [
    'label' => 'my_extension.db:conference.logo',
    'config' => [
      'type' => 'file',
      'maxitems' => 1,
      'allowed' => 'common-image-types',
      'relationship' => 'manyToOne',
    ],
  ],
  'impressions' => [
    'label' => 'my_extension.db:conference.impressions',
    'config' => [
      'type' => 'file',
      'allowed' => 'common-image-types',
      'overrideChildTca' => [
        'columns' => [
          'crop' => [
            'config' => [
              'cropVariants' => [
                'desktop' => [
                  'title' => 'my_extension.db:conference.impressions.desktop',
                  'allowedAspectRatios' => [
                    '16:9' => [
                      'title' => 'core.wizards:imwizard.ratio.16_9',
                      'value' => 16 / 9,
                    ],
                    'NaN' => [
                      'title' => 'core.wizards:imwizard.ratio.free',
                      'value' => 0.0,
                    ],
                  ],
                ],
                'mobile' => [
                  'title' => 'my_extension.db:conference.impressions.mobile',
                  'allowedAspectRatios' => [
                    '4:3' => [
                      'title' => 'core.wizards:imwizard.ratio.4_3',
                      'value' => 4 / 3,
                    ],
                  ],
                  // Initially the middle of the image, without the edges
                  'cropArea' => [
                    'x' => 0.1,
                    'y' => 0.1,
                    'width' => 0.8,
                    'height' => 0.8,
                  ],
                ],
              ],
              // A translated image keeps the crop of the default language,
              // unless the editors crop it anew
              'behaviour' => [
                'allowLanguageSynchronization' => true,
              ],
            ],
          ],
        ],
      ],
    ],
  ],
]);
$GLOBALS['TCA']['tx_myextension_conference']['palettes']['media'] = [
  'showitem' => 'logo, impressions',
];
ExtensionManagementUtility::addToAllTCAtypes(
  'tx_myextension_conference',
  '--palette--;;media',
  '',
  'before:--div--;core.form.tabs:categories',
);
Copied!

The logo can then be output without a loop:

EXT:my_extension/Resources/Private/Templates/Conference.html
<f:image image="{conference.logo}" />
Copied!