‪TYPO3CMS  9.5
TYPO3\CMS\Core\Utility\File\BasicFileUtility Class Reference
Inheritance diagram for TYPO3\CMS\Core\Utility\File\BasicFileUtility:
TYPO3\CMS\Core\Utility\File\ExtendedFileUtility

Public Member Functions

 setFileExtensionPermissions ($allowedFilePermissions, $deniedFilePermissions)
 
bool checkIfAllowed ($ext, $_, $filename='')
 
string getUniqueName ($theFile, $theDest, $dontCheckForUnique=false)
 
string cleanFileName ($fileName)
 

Public Attributes

const UNSAFE_FILENAME_CHARACTER_EXPRESSION = '\\x00-\\x2C\\/\\x3A-\\x3F\\x5B-\\x60\\x7B-\\xBF'
 
int $maxNumber = 99
 
int $uniquePrecision = 6
 

Protected Member Functions

bool is_allowed ($fileExtension)
 
bool string is_directory ($theDir)
 

Protected Attributes

array $fileExtensionPermissions
 

Detailed Description

Contains class with basic file management functions

Contains functions for management, validation etc of files in TYPO3.

Note: All methods in this class should not be used anymore since TYPO3 6.0. Please use corresponding \TYPO3\CMS\Core\Resource\ResourceStorage (fetched via BE_USERS->getFileStorages()), as all functions should be found there (in a cleaner manner).

Definition at line 31 of file BasicFileUtility.php.

Member Function Documentation

◆ checkIfAllowed()

bool TYPO3\CMS\Core\Utility\File\BasicFileUtility::checkIfAllowed (   $ext,
  $_,
  $filename = '' 
)

If the filename is given, check it against the TYPO3_CONF_VARS[BE][fileDenyPattern] + Checks if the $ext fileextension is allowed

Parameters
string$extFile extension, eg. "php" or "html
string$_‪not in use anymore
string$filename‪Filename to check against TYPO3_CONF_VARS[BE][fileDenyPattern]
Returns
‪bool TRUE if extension/filename is allowed
Todo:
‪Deprecate, but still in use by DataHandler
Deprecated:
‪but still in use in the Core. Don't use in your extensions!

Definition at line 119 of file BasicFileUtility.php.

References TYPO3\CMS\Core\Utility\File\BasicFileUtility\is_allowed().

Referenced by TYPO3\CMS\Impexp\Import\writeFileVerify().

◆ cleanFileName()

string TYPO3\CMS\Core\Utility\File\BasicFileUtility::cleanFileName (   $fileName)

Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_' Trailing dots are removed

Parameters
string$fileName‪Input string, typically the body of a filename
Returns
‪string Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_' and trailing dots removed
Todo:
‪Deprecate, but still in use by the core
Deprecated:
‪but still in use in the Core. Don't use in your extensions!

Definition at line 209 of file BasicFileUtility.php.

References $GLOBALS.

◆ getUniqueName()

string TYPO3\CMS\Core\Utility\File\BasicFileUtility::getUniqueName (   $theFile,
  $theDest,
  $dontCheckForUnique = false 
)

Returns the destination path/filename of a unique filename/foldername in that path. 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
string$theFile‪The input filename to check
string$theDest‪The directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute.
bool$dontCheckForUnique‪If set the filename is returned with the path prepended without checking whether it already existed!
Returns
‪string The destination absolute filepath (not just the name!) of a unique filename/foldername in that path.
See also
‪\TYPO3\CMS\Core\DataHandling\DataHandler::checkValue()
Todo:
‪Deprecate, but still in use by the Core (DataHandler...)
Deprecated:
‪but still in use in the Core. Don't use in your extensions!

Definition at line 155 of file BasicFileUtility.php.

References TYPO3\CMS\Core\Utility\File\BasicFileUtility\is_directory().

Referenced by TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile(), and TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile_createRelFile().

◆ is_allowed()

bool TYPO3\CMS\Core\Utility\File\BasicFileUtility::is_allowed (   $fileExtension)
protected

Checks if a $fileExtension is allowed according to $this->fileExtensionPermissions.

Parameters
string$fileExtension‪The extension to check, eg. "php" or "html" etc.
Returns
‪bool TRUE if file extension is allowed.

Definition at line 83 of file BasicFileUtility.php.

Referenced by TYPO3\CMS\Core\Utility\File\BasicFileUtility\checkIfAllowed().

◆ is_directory()

bool string TYPO3\CMS\Core\Utility\File\BasicFileUtility::is_directory (   $theDir)
protected

Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server.

Parameters
string$theDir‪Directory path to check
Returns
‪bool|string Returns the cleaned up directory name if OK, otherwise FALSE.

Definition at line 130 of file BasicFileUtility.php.

References TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath().

Referenced by TYPO3\CMS\Core\Utility\File\BasicFileUtility\getUniqueName().

◆ setFileExtensionPermissions()

TYPO3\CMS\Core\Utility\File\BasicFileUtility::setFileExtensionPermissions (   $allowedFilePermissions,
  $deniedFilePermissions 
)

Sets the file permissions, used in DataHandler e.g.

Parameters
string$allowedFilePermissions
string$deniedFilePermissions

Definition at line 71 of file BasicFileUtility.php.

Member Data Documentation

◆ $fileExtensionPermissions

array TYPO3\CMS\Core\Utility\File\BasicFileUtility::$fileExtensionPermissions
protected
Initial value:
= array(
'allow' => '*',
'deny' => PHP_EXTENSIONS_DEFAULT
)

Allowed and denied file extensions

Definition at line 53 of file BasicFileUtility.php.

◆ $maxNumber

int TYPO3\CMS\Core\Utility\File\BasicFileUtility::$maxNumber = 99

This number decides the highest allowed appended number used on a filename before we use naming with unique strings

Definition at line 42 of file BasicFileUtility.php.

◆ $uniquePrecision

int TYPO3\CMS\Core\Utility\File\BasicFileUtility::$uniquePrecision = 6

This number decides how many characters out of a unique MD5-hash that is appended to a filename if getUniqueName is asked to find an available filename.

Definition at line 48 of file BasicFileUtility.php.

◆ UNSAFE_FILENAME_CHARACTER_EXPRESSION

const TYPO3\CMS\Core\Utility\File\BasicFileUtility::UNSAFE_FILENAME_CHARACTER_EXPRESSION = '\\x00-\\x2C\\/\\x3A-\\x3F\\x5B-\\x60\\x7B-\\xBF'

Definition at line 36 of file BasicFileUtility.php.