Core API

3.3.5. Files: t3lib_extFileFunctions basics

File operations in TCE is handled by the class "t3lib_extFileFunctions" which extends "t3lib_basicFileFunctions". The instructions for file manipulation is passed to this class as a multidimensional array.

Files Array ($file):

Syntax:

  $file[ command ][ index ][ key ] = value
   

Description of keywords in syntax:

Key

Data type

Description

command

string (command keyword)

The command type you want to execute.

See table below for command keywords, keys and values

index

integer

Integer index in the array which separates multiple commands of the same type.

key

string

Depending on the command type. The keys will carry the information needed to perform the action. Typically a "target" key is used to point to the target directory or file while a "data" key carries the data.

See table below for command keywords, keys and values

value

string

The value for the command

See table below for command keywords, keys and values

   

Command keywords and values:

Command

Keys

Value

delete

"data"

"data" = Absolute path to the file/folder to delete

copy

"data"

"target"

"altName"

"data" = Absolute path to the file/folder to copy

"target" = Absolute path to the folder to copy to (destination)

"altName" = (boolean): If set, a new filename is made by appending numbers/unique-string in case the target already exists.

move

"data"

"target"

"altName"

(Exactly like copy, just replace the word "copy" with "move")

rename

"data"

"target"

"data" = New name, max 30 characters alphanumeric

"target" = Absolute path to the target file/folder

newfolder

"data"

"target"

"data" = Folder name, max 30 characters alphanumeric

"target" = Absolute path to the folder where to create it

newfile

"data"

"target"

"data" = New filename

"target" = Absolute path to the folder where to create it

editfile

"data"

"target"

"data" = The new content

"target" = Absolute path to the target file

upload

"data"

"target"

upload_$id

"data" = ID-number (points to the global var that holds the filename-ref  ($GLOBALS["HTTP_POST_FILES"]["upload_".$id]["name"])

"target" = Absolute path to the target folder (destination)

upload_$id = File reference. $id must equal value of file[upload][...][data]!

 

See t3lib_t3lib_extFileFunctions::func_upload()

unzip

"data"

"target"

"data" = Absolute path to the zip-file. (fileextension must be "zip")

"target" = The absolute path to the target folder (destination) (if not set, default is the same as the zip-file)

 

It is unlikely that you will need to use this internally in your scripts like you will need t3lib_TCEmain. It is fairly uncommon to need the file manipulations in own scripts unless you make a special application. Therefore the most typical usage of this API is from tce_file.php and the core scripts that are activated by the "File > List" module.

However, if you need it this is an example (taken from tce_file.php) of how to initialize the usage.

 

     1:     // Initializing:
     2: $this->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
     3: $this->fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
     4: $this->fileProcessor->init_actionPerms($BE_USER->user['fileoper_perms']);
     5: 
     6: $this->fileProcessor->start($this->file);
     7: $this->fileProcessor->processData();

Line 2 makes an instance of the class and line 3 initializes the object with the filemounts of the current user and the array of allow/deny file extensions in web-space and ftp-space (see below). Then the file operation permissions are loaded from the user object in line 4. Finally, the file command array is loaded in line 6 (and internally additional configuration takes place from $TYPO3_CONF_VARS!). In line 7 the command map is executed.

Web-space, Ftp-space and $TYPO3_CONF_VARS['BE']['fileExtensions']

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 matched. If no fileextension, true is returned if 'allow' is '*', false if 'deny' is '*' and true if none of these matches. This (default) configuration below accepts everything in ftpspace and everything in webspace except php3 or php files:

 

  $TYPO3_CONF_VARS['BE']['fileExtensions'] = array (
      'webspace' => array('allow'=>'', 'deny'=>'php3,php'),
      'ftpspace' => array('allow'=>'*', 'deny'=>'')
  );

 

To top


Valid XHTML 1.0!