‪TYPO3CMS  ‪main
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

string null 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 string sanitizeFolderPath ($theDir)
 

Detailed Description

Contains class with basic file management functions

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

All methods in this class should not be used anymore since TYPO3 6.0, this class is therefore marked as internal. 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 36 of file BasicFileUtility.php.

Member Function Documentation

◆ 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

May be removed without further notice. Method has been marked as deprecated for various versions but is still used in core.

Definition at line 134 of file BasicFileUtility.php.

References $GLOBALS.

◆ getUniqueName()

string null 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|null The destination absolute filepath (not just the name!) of a unique filename/foldername in that path.

May be removed without further notice. Method has been marked as deprecated for various versions but is still used in core.

Todo:
‪: should go into the LocalDriver in a protected way (not important to the outside world)

Definition at line 86 of file BasicFileUtility.php.

References TYPO3\CMS\Core\Utility\StringUtility\getUniqueId(), and TYPO3\CMS\Core\Utility\File\BasicFileUtility\sanitizeFolderPath().

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

◆ sanitizeFolderPath()

bool string TYPO3\CMS\Core\Utility\File\BasicFileUtility::sanitizeFolderPath (   $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.
Todo:
‪: should go into the LocalDriver in a protected way (not important to the outside world)

Definition at line 62 of file BasicFileUtility.php.

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

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

Member Data Documentation

◆ $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 47 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 53 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 41 of file BasicFileUtility.php.