TYPO3  7.6
Public Member Functions | Public Attributes | List of all members
BasicFileUtility Class Reference
Inheritance diagram for BasicFileUtility:
ExtendedFileUtility

Public Member Functions

 init ($mounts, $f_ext)
 
 is_allowed ($iconkey, $type)
 
 checkIfFullAccess ($theDest)
 
 is_webpath ($path)
 
 checkIfAllowed ($ext, $theDest, $filename= '')
 
 is_directory ($theDir)
 
 getUniqueName ($theFile, $theDest, $dontCheckForUnique=0)
 
 checkPathAgainstMounts ($thePath)
 
 findFirstWebFolder ()
 
 slashPath ($path)
 
 cleanFileName ($fileName, $charset= '')
 

Public Attributes

const UNSAFE_FILENAME_CHARACTER_EXPRESSION = '\\x00-\\x2C\\/\\x3A-\\x3F\\x5B-\\x60\\x7B-\\xBF'
 
 $getUniqueNamePrefix = ''
 
 $maxNumber = 99
 
 $uniquePrecision = 6
 
 $maxInputNameLen = 60
 
 $tempFN = '_temp_'
 
 $f_ext = array()
 
 $mounts = array()
 
 $webPath = ''
 
 $isInit = 0
 
 $csConvObj
 

Detailed Description

Contains class with basic file management functions

Contains functions for management, validation etc of files in TYPO3, using the concepts of web- and ftp-space. Please see the comment for the init() function

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 32 of file BasicFileUtility.php.

Member Function Documentation

checkIfAllowed (   $ext,
  $theDest,
  $filename = '' 
)

If the filename is given, check it against the TYPO3_CONF_VARS[BE][fileDenyPattern] + Checks if the $ext fileextension is allowed in the path $theDest (this is based on whether $theDest is below the $this->webPath)

Parameters
stringFile extension, eg. "php" or "html
stringAbsolute path for which to test
stringFilename 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 240 of file BasicFileUtility.php.

References $filename, BasicFileUtility\is_allowed(), BasicFileUtility\is_webpath(), and GeneralUtility\verifyFilenameAgainstDenyPattern().

checkIfFullAccess (   $theDest)

Returns TRUE if you can operate of ANY file ('*') in the space $theDest is in ('webspace' / 'ftpspace')

Parameters
stringAbsolute path
Returns
bool
Todo:
Deprecate: but still in use by through func_unzip in ExtendedFileUtility
Deprecated:
but still in use in the Core. Don't use in your extensions!

Definition at line 198 of file BasicFileUtility.php.

References BasicFileUtility\is_webpath().

Referenced by ExtendedFileUtility\func_unzip().

checkPathAgainstMounts (   $thePath)

Checks if $thePath is a path under one of the paths in $this->mounts See comment in the header of this class.

Parameters
string$thePathMUST HAVE a trailing '/' in order to match correctly with the mounts
Returns
string The key to the first mount found, otherwise nothing is returned.
See Also
init()
Todo:
: deprecate this function, now done in the Storage object. But still in use by impexp and ExtendedFileUtility
Deprecated:
but still in use in the Core. Don't use in your extensions!

Definition at line 332 of file BasicFileUtility.php.

References GeneralUtility\isFirstPartOfStr(), and GeneralUtility\validPathStr().

Referenced by ExtendedFileUtility\func_unzip().

cleanFileName (   $fileName,
  $charset = '' 
)

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
string$charsetCharset of the a filename (defaults to current charset; depending on context)
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 395 of file BasicFileUtility.php.

References $GLOBALS, elseif, and GeneralUtility\makeInstance().

findFirstWebFolder ( )

Find first web folder (relative to PATH_site.'fileadmin') in filemounts array

Returns
string The key to the first mount inside PATH_site."fileadmin" found, otherwise nothing is returned.
Todo:
: deprecate this function. But still in use by impexp
Deprecated:
but still in use in the Core. Don't use in your extensions!

Definition at line 350 of file BasicFileUtility.php.

References $GLOBALS, and GeneralUtility\isFirstPartOfStr().

getUniqueName (   $theFile,
  $theDest,
  $dontCheckForUnique = 0 
)

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. TCEmain when files are attached to records and needs to be uniquely named in the uploads/* folders

Parameters
stringThe input filename to check
stringThe directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute.
boolIf 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 278 of file BasicFileUtility.php.

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

init (   $mounts,
  $f_ext 
)

Constructor This function should be called to initialise the internal arrays $this->mounts and $this->f_ext

A typical example of the array $mounts is this: $mounts[xx][path] = (..a mounted path..) the 'xx'-keys is just numerical from zero. There are also a [name] and [type] value that just denotes the mountname and type. Not used for athentication here. $this->mounts is traversed in the function checkPathAgainstMounts($thePath), and it is checked that $thePath is actually below one of the mount-paths The mountpaths are with a trailing '/'. $thePath must be with a trailing '/' also! As you can see, $this->mounts is very critical! This is the array that decides where the user will be allowed to copy files!!

A typical example of the array $f_ext is this: $f_ext['webspace']['allow']=''; $f_ext['webspace']['deny']= PHP_EXTENSIONS_DEFAULT; $f_ext['ftpspace']['allow']='*'; $f_ext['ftpspace']['deny']=''; The control of fileextensions goes in two catagories. Webspace and Ftpspace. Webspace is folders accessible from a webbrowser (below TYPO3_DOCUMENT_ROOT) and ftpspace is everything else. The control is done like this: If an extension matches 'allow' then the check returns TRUE. If not and an extension matches 'deny' then the check return FALSE. If no match at all, returns TRUE. You list extensions comma-separated. If the value is a '*' every extension is allowed The list is case-insensitive when used in this class (see init()) Typically TYPO3_CONF_VARS['BE']['fileExtensions'] would be passed along as $f_ext.

Example: $basicff->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);

Parameters
arrayNot in use anymore
arrayArray with information about allowed and denied file extensions. Typically passed: $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']
Returns
void

Definition at line 139 of file BasicFileUtility.php.

References BasicFileUtility\$f_ext, $GLOBALS, BasicFileUtility\$maxInputNameLen, BasicFileUtility\$mounts, GeneralUtility\getIndpEnv(), and GeneralUtility\uniqueList().

is_allowed (   $iconkey,
  $type 
)

Checks if a $iconkey (fileextension) is allowed according to $this->f_ext.

Parameters
stringThe extension to check, eg. "php" or "html" etc.
stringEither "webspage" or "ftpspace" - points to a key in $this->f_ext
Returns
bool TRUE if file extension is allowed.
Todo:
Deprecate, but still in use by checkIfAllowed()
Deprecated:
but still in use in the Core. Don't use in your extensions!

Definition at line 161 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.

Parameters
stringDirectory path to check
Returns
string Returns the cleaned up directory name if OK, otherwise FALSE.
Todo:
Deprecate: but still in use by getUniqueName (used by DataHandler)
Deprecated:
but still in use in the Core. Don't use in your extensions!

Definition at line 253 of file BasicFileUtility.php.

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

Referenced by ExtendedFileUtility\func_unzip(), and BasicFileUtility\getUniqueName().

is_webpath (   $path)

Checks if $this->webPath (should be TYPO3_DOCUMENT_ROOT) is in the first part of $path Returns TRUE also if $this->init is not set or if $path is empty...

Parameters
stringAbsolute path to check
Returns
bool
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 217 of file BasicFileUtility.php.

References GeneralUtility\isFirstPartOfStr(), and BasicFileUtility\slashPath().

Referenced by BasicFileUtility\checkIfAllowed(), and BasicFileUtility\checkIfFullAccess().

slashPath (   $path)

Returns a string which has a slash '/' appended if it doesn't already have that slash

Parameters
stringInput string
Returns
string Output string with a slash in the end (if not already there)
Todo:
Deprecate, but still in use by is_webpath, used by DataHandler
Deprecated:
but still in use in the Core. Don't use in your extensions!

Definition at line 375 of file BasicFileUtility.php.

Referenced by BasicFileUtility\is_webpath().

Member Data Documentation

$csConvObj

Definition at line 103 of file BasicFileUtility.php.

$f_ext = array()

Definition at line 77 of file BasicFileUtility.php.

Referenced by BasicFileUtility\init().

$getUniqueNamePrefix = ''

Definition at line 44 of file BasicFileUtility.php.

$isInit = 0

Definition at line 98 of file BasicFileUtility.php.

$maxInputNameLen = 60

Definition at line 65 of file BasicFileUtility.php.

Referenced by BasicFileUtility\init().

$maxNumber = 99

Definition at line 51 of file BasicFileUtility.php.

$mounts = array()

Definition at line 84 of file BasicFileUtility.php.

Referenced by BasicFileUtility\init().

$tempFN = '_temp_'

Definition at line 72 of file BasicFileUtility.php.

$uniquePrecision = 6

Definition at line 58 of file BasicFileUtility.php.

$webPath = ''

Definition at line 91 of file BasicFileUtility.php.

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

Definition at line 37 of file BasicFileUtility.php.