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

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

Parameters
string$extFile extension, eg. "php" or "html
string$_not in use anymore
string$filenameFilename 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 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

Parameters
string$fileNameInput 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 218 of file BasicFileUtility.php.

References $GLOBALS, and GeneralUtility\makeInstance().

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$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!
Returns
string The destination absolute filepath (not just the name!) of a unique filename/foldername in that path.
See also
::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 164 of file BasicFileUtility.php.

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

is_allowed (   $fileExtension)
protected

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

Parameters
string$fileExtensionThe extension to check, eg. "php" or "html" etc.
Returns
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)
protected

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

Parameters
string$theDirDirectory path to check
Returns
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,
  $deniedFilePermissions 
)

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

Parameters
string$allowedFilePermissions
string$deniedFilePermissions

Definition at line 80 of file BasicFileUtility.php.

References GeneralUtility\uniqueList().

Member Data Documentation

$fileExtensionPermissions = []
protected

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.