TYPO3
7.6
|
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 | |
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.
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)
string | File extension, eg. "php" or "html |
string | Absolute path for which to test |
string | Filename to check against TYPO3_CONF_VARS[BE][fileDenyPattern] |
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')
string | Absolute path |
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.
string | $thePath | MUST HAVE a trailing '/' in order to match correctly with the mounts |
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
string | $fileName | Input string, typically the body of a filename |
string | $charset | Charset of the a filename (defaults to current charset; depending on context) |
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
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
string | The input filename to check |
string | The directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute. |
bool | If set the filename is returned with the path prepended without checking whether it already existed! |
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']);
array | Not in use anymore |
array | Array with information about allowed and denied file extensions. Typically passed: $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions'] |
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.
string | The extension to check, eg. "php" or "html" etc. |
string | Either "webspage" or "ftpspace" - points to a key in $this->f_ext |
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.
string | Directory path to check |
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...
string | Absolute path to check |
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
string | Input string |
Definition at line 375 of file BasicFileUtility.php.
Referenced by BasicFileUtility\is_webpath().
$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.