Reputation: 53
I have a file upload field in the TCA of an extension. I want to restrict the type of uploadable files through that field. Only "pdf" or any other document file types (Eg: doc,xls,rar,zip etc) must be uploaded in that field. All other file types must be prevented (Eg: image,video etc). How can I do that ?
Upvotes: 1
Views: 3444
Reputation: 3229
In newer TYPO3 versions, some field types have been replaced, so right now it depends on your TYPO3 version and what functionality is to be used.
What is interesting to note is that TYPO3 changed how to include / exclude things in various places, in newer versions you usually do not define what to exclude, you define what to include.
Since TYPO3 v12, you have the "file" type. Here, you can use 'allowed' to define which file extensions are allowed. In the following snippet, only type "png" is allowed.
Example as Flexform:
<settings.file>
<TCEforms>
<label>Some title or language label</label>
<config>
<type>file</type>
<maxitems>1</maxitems>
<allowed>png</allowed>
</config>
</TCEforms>
</settings.file>
Also, since TYPO3 v12, you have the type='link'. This replaces the previous type='input' renderType='inputLink' (but the properties have also changed - migrations exist, but you should use the correct properties in the future!).
This gives you more options than "file", you can also use it to select pages, enter a URL etc. Which files you can used is defined with allowedFileExtensions.
Example as Flexform:
<settings.link>
<TCEforms>
<label>Some title or language label</label>
<config>
<type>link</type>
<!--
This defines, what you can select in the link browser.
!!! Is not a csv string (as before in inputLink), but an array!!!
-->
<allowedTypes>
<numIndex index="0">file</numIndex>
<numIndex index="1">url</numIndex>
</allowedTypes>
<appearance>
<enableBrowser>true</enableBrowser>
<browserTitle>Select file or URL</browserTitle>
<!--
is not a csv string (as in inputLink), but an array!!!
-->
<allowedFileExtensions>
<numIndex index="0">png</numIndex>
</allowedFileExtensions>
<!--
!!! important, <allowedOptions must contain the numIndex,
just using
<allowedOption></allowedOption> is not sufficient
-->
<allowedOptions>
<numIndex index="0"></numIndex>
</allowedOptions>
</appearance>
</config>
</TCEforms>
</settings.file>
For previous TYPO3 versions, see type='input', renderType='inputLink'.
Upvotes: 0
Reputation: 6164
You need to add the overrideChildTca
and filter
to your TCA configuration to override the allowed file extensions, like it is described on https://docs.typo3.org/m/typo3/reference-tca/9.5/en-us/ColumnsConfig/Type/Inline.html#file-abstraction-layer
Upvotes: 2