All Classes Namespaces Files Functions Variables Pages
BasicFileUtility Class Reference
Inheritance diagram for BasicFileUtility:

Public Member Functions

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

Public Attributes

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

Protected Member Functions

 is_allowed ($fileExtension)
 is_directory ($theDir)

Protected Attributes

 $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 (fetched via BE_USERS->getFileStorages()), as all functions should be found there (in a cleaner manner).

Definition at line 31 of file BasicFileUtility.php.

Constructor & Destructor Documentation

__construct ( )

Constructor, Initializes the internal array $this->fileExtensionPermissions based on TYPO3_CONF_VARS

Definition at line 68 of file BasicFileUtility.php.

References $GLOBALS, and GeneralUtility\uniqueList().

Member Function Documentation

checkIfAllowed (   $ext,
  $filename = '' 

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

string$extFile extension, eg. "php" or "html
string$_not in use anymore
string$filenameFilename to check against TYPO3_CONF_VARS[BE][fileDenyPattern]
bool TRUE if extension/filename is allowed
Deprecate, but still in use by DataHandler
but still in use in the Core. Don't use in your extensions!

Definition at line 128 of file BasicFileUtility.php.

References BasicFileUtility\is_allowed(), and GeneralUtility\verifyFilenameAgainstDenyPattern().

cleanFileName (   $fileName)

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

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

Definition at line 218 of file BasicFileUtility.php.

References $GLOBALS, and GeneralUtility\makeInstance().

getUniqueName (   $theFile,
  $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

string$theFileThe input filename to check
string$theDestThe directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute.
bool$dontCheckForUniqueIf set the filename is returned with the path prepended without checking whether it already existed!
string The destination absolute filepath (not just the name!) of a unique filename/foldername in that path.
See also
Deprecate, but still in use by the Core (DataHandler...)
but still in use in the Core. Don't use in your extensions!

Definition at line 164 of file BasicFileUtility.php.

References BasicFileUtility\$maxNumber, BasicFileUtility\is_directory(), and GeneralUtility\split_fileref().

is_allowed (   $fileExtension)

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

string$fileExtensionThe extension to check, eg. "php" or "html" etc.
bool TRUE if file extension is allowed.

Definition at line 92 of file BasicFileUtility.php.

References GeneralUtility\inList().

Referenced by BasicFileUtility\checkIfAllowed().

is_directory (   $theDir)

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

string$theDirDirectory path to check
bool|string Returns the cleaned up directory name if OK, otherwise FALSE.

Definition at line 139 of file BasicFileUtility.php.

References PathUtility\getCanonicalPath(), and GeneralUtility\validPathStr().

Referenced by BasicFileUtility\getUniqueName().

setFileExtensionPermissions (   $allowedFilePermissions,

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


Definition at line 80 of file BasicFileUtility.php.

References GeneralUtility\uniqueList().

Member Data Documentation

$fileExtensionPermissions = []

Definition at line 56 of file BasicFileUtility.php.

$maxNumber = 99

Definition at line 43 of file BasicFileUtility.php.

Referenced by BasicFileUtility\getUniqueName().

$uniquePrecision = 6

Definition at line 50 of file BasicFileUtility.php.

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

Definition at line 36 of file BasicFileUtility.php.