TYPO3 CMS  TYPO3_6-2
TYPO3\CMS\Core\Utility\File\ExtendedFileUtility Class Reference
Inheritance diagram for TYPO3\CMS\Core\Utility\File\ExtendedFileUtility:
TYPO3\CMS\Core\Utility\File\BasicFileUtility t3lib_extFileFunctions

Public Member Functions

 start ($fileCmds)
 
 init_actionPerms ()
 
 setActionPermissions (array $permissions=array())
 
 processData ()
 
 printLogErrorMessages ($redirect='')
 
 pushErrorMessagesToFlashMessageQueue ()
 
 getErrorMessages ()
 
 findRecycler ($theFile)
 
 writeLog ($action, $error, $details_nr, $details, $data)
 
 func_rename ($cmds)
 
 func_newfolder ($cmds)
 
 func_newfile ($cmds)
 
 func_edit ($cmds)
 
 func_unzip ($cmds)
 
- Public Member Functions inherited from TYPO3\CMS\Core\Utility\File\BasicFileUtility
 init ($mounts, $f_ext)
 
 getTotalFileInfo ($wholePath)
 
 is_allowed ($iconkey, $type)
 
 checkIfFullAccess ($theDest)
 
 is_webpath ($path)
 
 checkIfAllowed ($ext, $theDest, $filename='')
 
 checkFileNameLen ($fileName)
 
 is_directory ($theDir)
 
 isPathValid ($theFile)
 
 getUniqueName ($theFile, $theDest, $dontCheckForUnique=0)
 
 checkPathAgainstMounts ($thePath)
 
 findFirstWebFolder ()
 
 blindPath ($thePath)
 
 findTempFolder ()
 
 cleanDirectoryName ($theDir)
 
 rmDoubleSlash ($string)
 
 slashPath ($path)
 
 cleanFileName ($fileName, $charset='')
 

Public Attributes

 $unzipPath = ''
 
 $dontCheckForUnique = 0
 
 $actionPerms
 
 $recyclerFN = '_recycler_'
 
 $useRecycler = 1
 
 $internalUploadMap = array()
 
 $lastError = ''
 
- Public Attributes inherited from TYPO3\CMS\Core\Utility\File\BasicFileUtility
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
 

Protected Member Functions

 transformFileReferenceToRecordReference (array $referenceRecord)
 
 getFileObject ($identifier)
 
 func_move ($cmds)
 
 getIndexer (\TYPO3\CMS\Core\Resource\ResourceStorage $storage)
 
 getDatabaseConnection ()
 
 getBackendUser ()
 

Protected Attributes

 $errorMessages = array()
 
 $fileCmdMap
 
 $fileFactory
 

Detailed Description

Contains functions for performing file operations like copying, pasting, uploading, moving, deleting etc. through the TCE

See document "TYPO3 Core API" for syntax

This class contains functions primarily used by tce_file.php (TYPO3 Core Engine for file manipulation) Functions include copying, moving, deleting, uploading and so on...

Important internal variables:

$filemounts (see basicFileFunctions) $f_ext (see basicFileFunctions)

All fileoperations must be within the filemount-paths. Further the fileextension MUST validate TRUE with the f_ext array

The unzip-function allows unzip only if the destination path has it's f_ext[]['allow'] set to '*'!! You are allowed to copy/move folders within the same 'space' (web/ftp). You are allowed to copy/move folders between spaces (web/ftp) IF the destination has it's f_ext[]['allow'] set to '*'!

Advice: You should always exclude php-files from the webspace. This will keep people from uploading, copy/moving and renaming files to become executable php scripts. You should never mount a ftp_space 'below' the webspace so that it reaches into the webspace. This is because if somebody unzips a zip-file in the ftp-space so that it reaches out into the webspace this will be a violation of the safety For example this is a bad idea: you have an ftp-space that is '/www/' and a web-space that is '/www/htdocs/'

Author
Kasper Skårhøj kaspe.nosp@m.rYYY.nosp@m.Y@typ.nosp@m.o3.c.nosp@m.om

Definition at line 53 of file ExtendedFileUtility.php.

Member Function Documentation

◆ findRecycler()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::findRecycler (   $theFile)

Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually 'recycler') is present. If a folder in the tree happens to be a recycler-folder (which means that we're deleting something inside a recycler-folder) this is ignored

Parameters
string$theFileTakes a valid Path ($theFile)
Returns
string Returns the path (without trailing slash) of the closest recycle-folder if found. Else FALSE.
Todo:

To be put in Storage with a better concept

Define visibility

Deprecated:
since TYPO3 6.0, use method instead

Definition at line 333 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\$recyclerFN, TYPO3\CMS\Core\Utility\File\BasicFileUtility\checkPathAgainstMounts(), TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath(), TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction(), TYPO3\CMS\Core\Utility\GeneralUtility\split_fileref(), and TYPO3\CMS\Core\Utility\GeneralUtility\validPathStr().

◆ func_edit()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_edit (   $cmds)

Editing textfiles or folders (action=9)

Parameters
array$cmds$cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
Returns
boolean Returns TRUE on success
Todo:
Define visibility

Definition at line 902 of file ExtendedFileUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getFileObject(), TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getIndexer(), TYPO3\CMS\Core\Resource\ResourceFactory\getInstance(), and TYPO3\CMS\Core\Utility\GeneralUtility\inList().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

◆ func_move()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_move (   $cmds)
protected

Moving files and folders (action=3)

$cmds['data'] (string): The file/folder to move

  • example "4:mypath/tomyfolder/myfile.jpg")
  • for backwards compatibility: the identifier was the path+filename $cmds['target'] (string): The path where to move to.
  • example "2:targetpath/targetfolder/" $cmds['altName'] (string): Use an alternative name if the target already exists
Parameters
array$cmdsCommand details as described above
Returns

Definition at line 696 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getFileObject().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

◆ func_newfile()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_newfile (   $cmds)

This creates a new file. (action=8) $cmds['data'] (string): The new file name $cmds['target'] (string): The path where to create it.

  • example "2:targetpath/targetfolder/"
Parameters
array$cmdsCommand details as described above
Returns
string Returns the new filename upon success
Todo:
Define visibility

Definition at line 865 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getFileObject(), and TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\writeLog().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

◆ func_newfolder()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_newfolder (   $cmds)

This creates a new folder. (action=6)

$cmds['data'] (string): The new folder name $cmds['target'] (string): The path where to copy to.

  • example "2:targetpath/targetfolder/"
Parameters
array$cmdsCommand details as described above
Returns
Returns the new foldername upon success
Todo:
Define visibility

Definition at line 829 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getFileObject().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

◆ func_rename()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_rename (   $cmds)

Renaming files or foldes (action=5)

$cmds['data'] (string): The file/folder to copy

  • example "4:mypath/tomyfolder/myfile.jpg")
  • for backwards compatibility: the identifier was the path+filename $cmds['target'] (string): New name of the file/folder
Parameters
array$cmdsCommand details as described above
Returns
Returns the new file upon success
Todo:
Define visibility

Definition at line 776 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getFileObject().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

◆ func_unzip()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_unzip (   $cmds)

Unzipping file (action=7) This is permitted only if the user has fullAccess or if the file resides

Parameters
array$cmds$cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
Returns
boolean Returns TRUE on success
Todo:
Define visibility

Definition at line 1042 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\BasicFileUtility\checkIfFullAccess(), TYPO3\CMS\Core\Utility\File\BasicFileUtility\checkPathAgainstMounts(), TYPO3\CMS\Core\Utility\CommandUtility\exec(), TYPO3\CMS\Core\Utility\File\BasicFileUtility\is_directory(), TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance(), and TYPO3\CMS\Core\Utility\GeneralUtility\split_fileref().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

◆ getBackendUser()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::getBackendUser ( )
protected
Returns

Definition at line 1125 of file ExtendedFileUtility.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\writeLog().

◆ getDatabaseConnection()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::getDatabaseConnection ( )
protected

◆ getErrorMessages()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::getErrorMessages ( )

Return all error messages from the file operations of this script instance

Returns
array all errorMessages as a numerical array

Definition at line 319 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\$errorMessages.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\pushErrorMessagesToFlashMessageQueue().

◆ getFileObject()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::getFileObject (   $identifier)
protected

◆ getIndexer()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::getIndexer ( \TYPO3\CMS\Core\Resource\ResourceStorage  $storage)
protected

Gets Indexer

Parameters
\TYPO3\CMS\Core\Resource\ResourceStorage$storage
Returns

Definition at line 1109 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\func_edit().

◆ init_actionPerms()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::init_actionPerms ( )

Sets up permission to perform file/directory operations. See below or the be_user-table for the significance of the various bits in $setup.

Returns
void
Deprecated:
since 6.2 will be removed two versions later. Use ExtendedFileUtility::setActionPermissions() instead

Definition at line 169 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction(), and TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\setActionPermissions().

◆ printLogErrorMessages()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::printLogErrorMessages (   $redirect = '')

Adds log error messages from the operations of this script instance to the FlashMessageQueue

Parameters
string$redirectRedirect URL (for creating link in message)
Returns
void
Deprecated:
since TYPO3 6.1, will be removed two versions later, use ->pushErrorMessagesToFlashMessageQueue directly instead

Definition at line 291 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction(), and TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\pushErrorMessagesToFlashMessageQueue().

◆ processData()

◆ pushErrorMessagesToFlashMessageQueue()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::pushErrorMessagesToFlashMessageQueue ( )

Adds all log error messages from the operations of this script instance to the FlashMessageQueue

Returns
void

Definition at line 301 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR, TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getErrorMessages(), and TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\printLogErrorMessages().

◆ setActionPermissions()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::setActionPermissions ( array  $permissions = array())

Sets the file action permissions. If no argument is given, permissions of the currently logged in backend user are taken into account.

Parameters
array$permissionsFile Permissions.

Definition at line 180 of file ExtendedFileUtility.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\init_actionPerms().

◆ start()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::start (   $fileCmds)

Initialization of the class

Parameters
array$fileCmdsArray with the commands to execute. See "TYPO3 Core API" document
Returns
void
Todo:
Define visibility

Definition at line 149 of file ExtendedFileUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\$unzipPath, and TYPO3\CMS\Core\Resource\ResourceFactory\getInstance().

◆ transformFileReferenceToRecordReference()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::transformFileReferenceToRecordReference ( array  $referenceRecord)
protected

Maps results from the fal file reference table on the structure of the normal reference index table.

Parameters
array$referenceRecord
Returns
array

Definition at line 572 of file ExtendedFileUtility.php.

References TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getDatabaseConnection().

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\writeLog().

◆ writeLog()

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::writeLog (   $action,
  $error,
  $details_nr,
  $details,
  $data 
)

Logging file operations

Parameters
integer$actionThe action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
integer$errorThe severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
integer$details_nrThis number is unique for every combination of $type and $action. This is the error-message number, which can later be used to translate error messages.
string$detailsThis is the default, raw error message in english
array$dataArray with special information that may go into $details by "%s" marks / sprintf() when the log is shown
Returns
void
Todo:
Define visibility

Definition at line 364 of file ExtendedFileUtility.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\$lastError, $result, TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR, TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getBackendUser(), TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getDatabaseConnection(), TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\getFileObject(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordPath(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle(), TYPO3\CMS\Backend\Utility\IconUtility\getSpriteIconForRecord(), TYPO3\CMS\Core\Messaging\AbstractMessage\INFO, TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance(), TYPO3\CMS\Core\Messaging\AbstractMessage\OK, TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\transformFileReferenceToRecordReference(), and TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\func_newfile(), and TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\processData().

Member Data Documentation

◆ $actionPerms

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$actionPerms
Initial value:
= array(
'addFile' => FALSE,
'readFile' => FALSE,
'writeFile' => FALSE,
'copyFile' => FALSE,
'moveFile' => FALSE,
'renameFile' => FALSE,
'unzipFile' => FALSE,
'deleteFile' => FALSE,
'addFolder' => FALSE,
'readFolder' => FALSE,
'writeFolder' => FALSE,
'copyFolder' => FALSE,
'moveFolder' => FALSE,
'renameFolder' => FALSE,
'deleteFolder' => FALSE,
'recursivedeleteFolder' => FALSE
)

This array is self-explaining (look in the class below). It grants access to the functions. This could be set from outside in order to enabled functions to users. See also the function setActionPermissions() which takes input directly from the user-record

Definition at line 74 of file ExtendedFileUtility.php.

◆ $dontCheckForUnique

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$dontCheckForUnique = 0
Todo:
Define visibility

Definition at line 67 of file ExtendedFileUtility.php.

◆ $errorMessages

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$errorMessages = array()
protected

◆ $fileCmdMap

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$fileCmdMap
protected

Definition at line 132 of file ExtendedFileUtility.php.

◆ $fileFactory

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$fileFactory
protected

Definition at line 139 of file ExtendedFileUtility.php.

◆ $internalUploadMap

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$internalUploadMap = array()
Todo:
Define visibility

Definition at line 115 of file ExtendedFileUtility.php.

◆ $lastError

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$lastError = ''
Todo:
Define visibility

Definition at line 120 of file ExtendedFileUtility.php.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\writeLog().

◆ $recyclerFN

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$recyclerFN = '_recycler_'
Todo:
Define visibility

Definition at line 99 of file ExtendedFileUtility.php.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\findRecycler().

◆ $unzipPath

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$unzipPath = ''
Todo:
Define visibility

Definition at line 61 of file ExtendedFileUtility.php.

Referenced by TYPO3\CMS\Core\Utility\File\ExtendedFileUtility\start().

◆ $useRecycler

TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::$useRecycler = 1

Definition at line 108 of file ExtendedFileUtility.php.