BasicFileUtility

class \TYPO3\CMS\Core\Utility\File\BasicFileUtility

Contains class with basic file management functions

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

Table of Contents

Constants

UNSAFE_FILENAME_CHARACTER_EXPRESSION  : string = '\x00-\x2C\/\x3A-\x3F\x5B-\x60\x7B-\xBF'

Properties

$maxNumber  : int
This number decides the highest allowed appended number used on a filename before we use naming with unique strings
$uniquePrecision  : int
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.

Methods

cleanFileName()  : string
Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_' Trailing dots are removed
getUniqueName()  : string|null
Returns the destination path/filename of a unique filename/foldername in that path.
sanitizeFolderPath()  : bool|string
Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server.

Constants

UNSAFE_FILENAME_CHARACTER_EXPRESSION

public string UNSAFE_FILENAME_CHARACTER_EXPRESSION = '\x00-\x2C\/\x3A-\x3F\x5B-\x60\x7B-\xBF'

Properties

$maxNumber

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

public int $maxNumber = 99

$uniquePrecision

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.

public int $uniquePrecision = 6

Methods

cleanFileName()

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

public cleanFileName(string $fileName) : string

Parameters

$fileName : string

Input string, typically the body of a filename

Return values

string —

Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_' and trailing dots removed

getUniqueName()

Returns the destination path/filename of a unique filename/foldername in that path.

public getUniqueName(string $theFile, string $theDest[, bool $dontCheckForUnique = false ]) : string|null

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

$theFile : string

The input filename to check

$theDest : string

The directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute.

$dontCheckForUnique : bool = false

If set the filename is returned with the path prepended without checking whether it already existed!

Tags

todo:

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

Return values

string|null —

The destination absolute filepath (not just the name!) of a unique filename/foldername in that path.

sanitizeFolderPath()

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

protected sanitizeFolderPath(string $theDir) : bool|string

Parameters

$theDir : string

Directory path to check

Tags

todo:

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

Return values

bool|string —

Returns the cleaned up directory name if OK, otherwise FALSE.

On this page