Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
eZContentUpload Class Reference

Handles simple creation of content objects by uploading files. More...

## Public Member Functions
| __construct ( $params=false)
| eZContentUpload ( $params=false)
| attributes ()
| hasAttribute ( $attributeName)
| attribute ( $attributeName)
| handleLocalFile (&$result, $filePath, $location, $existingNode, $nameString='', $localeCode=false)
| handleUpload (&$result, $httpFileIdentifier, $location, $existingNode, $nameString='', $localeCode=false, $publish=true)
| objectFileInfo ( $contentObject)
| fetchHTTPFile ( $httpFileIdentifier, &$errors, &$file, &$mimeData)
| setResult ( $result)
| findHandler (&$result, $mimeInfo)

## Static Public Member Functions
static | upload ( $parameters=array(), $module)
| nodeAliasID ( $nodeName)
static | result ( $actionName, $cleanup=true)
static | cleanup ( $actionName)
| cleanupAll ()

## Public Attributes
const | STATUS_PERMISSION_DENIED = 1
| $Parameters = false

## Private Member Functions
| publishObject (&$result, &$errors, &$notices, $object, $publishVersion, $class, $parentNodes, $parentMainNode)
| detectLocations ( $classIdentifier, $class, $location, &$parentNodes, &$parentMainNode)

## Static Private Member Functions
| findHTTPFileAttribute ( $dataMap, $fileAttribute)
| findRegularFileAttribute ( $dataMap, $fileAttribute)
| findStringAttribute ( $dataMap, $nameAttribute)
| detectClassIdentifier ( $mime)
| checkAccess ( $nodeID, $class)
| processNamePattern ( $variables, $namePattern)

## Detailed Description

Handles simple creation of content objects by uploading files.

This class makes it easy to use the start a new file upload and let it be created as a content object.

Using it is simply to call the upload function with some parameters.

eZContentUpload::upload( array( 'action_name' => 'MyActionName' ), $module );
eZContentUpload\upload
static upload( $parameters=array(), $module)
Definition: ezcontentupload.php:119

It requires the module objects as the second parameter to redirect and the first define how the upload page should behave. Normally you just want to set `action_name` and define the behaviour of that action in settings/upload.ini.

Fetching the result afterwards is done by calling the result() method, it will return the resulting node ID or object ID depending on the configuration of the upload action.

eZContentUpload::result( 'MyActionName' );
eZContentUpload\result
static result( $actionName, $cleanup=true)
Definition: ezcontentupload.php:1320

It is also possible to use this class to upload a given file (HTTP or regular) as an object. The correct class and location can be determined automatically.

Simply create an instance and then call handleUpload() or handleLocalFile().

$upload = new eZContentUpload();
$upload->handleUpload( $result, 'UploadFile', 'auto', false );
$upload->handleLocalFile( $result, 'a_yellow_flower.jpg', 'auto' );
eZContentUpload\eZContentUpload
eZContentUpload( $params=false)
Definition: ezcontentupload.php:78

Definition at line 48 of file ezcontentupload.php.

## Constructor & Destructor Documentation

## ◆ __construct()

eZContentUpload::__construct | ( |  | $params = `false` | ) |

Initializes the object with the session data if they are found. If $params is supplied it is used instead.

Parameters

  bool | $params |

Definition at line 59 of file ezcontentupload.php.

References eZHTTPTool\instance().

Referenced by eZContentUpload().

## Member Function Documentation

## ◆ attribute()

eZContentUpload::attribute | ( |  | $attributeName | ) |

Returns
  the attribute value of the attribute named $attributeName or `null` if no such attribute.

Definition at line 102 of file ezcontentupload.php.

References eZDebug\writeError().

Referenced by detectLocations().

## ◆ attributes()

eZContentUpload::attributes | ( |  | ) |

Returns
  an array with attribute names.

Definition at line 86 of file ezcontentupload.php.

## ◆ checkAccess()

eZContentUpload::checkAccess | ( |  | $nodeID,
|  |  | $class
| ) |  |
| static private

Definition at line 1179 of file ezcontentupload.php.

References eZContentObjectTreeNode\fetch().

Referenced by detectLocations().

## ◆ cleanup()

static eZContentUpload::cleanup | ( |  | $actionName | ) |
| static

Cleans up the persistent data and result for action named $actionName

Definition at line 1344 of file ezcontentupload.php.

References eZHTTPTool\instance().

Referenced by result().

## ◆ cleanupAll()

eZContentUpload::cleanupAll | ( |  | ) |
| static

Similar to cleanup() but removes persistent data from all actions.

Definition at line 1354 of file ezcontentupload.php.

References eZHTTPTool\instance().

## ◆ detectClassIdentifier()

eZContentUpload::detectClassIdentifier | ( |  | $mime | ) |
| static private

Figures out the class which should be used for file with MIME-Type $mime and returns the class identifier.

Parameters

  $mime | A string defining the MIME-Type, will be used to determine class identifier.

Definition at line 1015 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

## ◆ detectLocations()

eZContentUpload::detectLocations | ( |  | $classIdentifier,
|  |  | $class,
|  |  | $location,
|  | & | $parentNodes,
|  | & | $parentMainNode
| ) |  |
| private

Figures out the location(s) in which the class with the identifier $classIdentifier should be placed. The returned locations will either be a node ID or an identifier for a node (e.g. content).

Returns
  `true` if a location was found or `false` if no location could be determined

Parameters

  | $classIdentifier | Identifier of class, is used to determine location
  | $location | The wanted location, either use `'auto'` for automatic placement or number to determine to parent node ID.
  [out] | $parentNodes | Will contain an array with node IDs or identifiers if a location could be detected.
  [out] | $parentMainNode | Will contain the ID of the main node if a location could be detected.

Definition at line 1052 of file ezcontentupload.php.

References attribute(), checkAccess(), hasAttribute(), nodeAliasID(), and eZDebug\writeNotice().

Referenced by handleLocalFile(), and handleUpload().

## ◆ eZContentUpload()

eZContentUpload::eZContentUpload | ( |  | $params = `false` | ) |

Deprecated:
  Use eZContentUpload::__construct() instead

Parameters

  bool | $params |

Definition at line 78 of file ezcontentupload.php.

References __construct().

Referenced by result().

## ◆ fetchHTTPFile()

eZContentUpload::fetchHTTPFile | ( |  | $httpFileIdentifier,
|  | & | $errors,
|  | & | $file,
|  | & | $mimeData
| ) |  |

Fetches the HTTP-File into $file and fills in MIME-Type information into $mimeData.

Returns
  bool false if something went wrong.

Definition at line 873 of file ezcontentupload.php.

References eZHTTPFile\canFetch(), eZHTTPFile\fetch(), eZMimeType\findByFileContents(), ezpI18n\tr(), eZHTTPFile\UPLOADEDFILE_CANT_WRITE, eZHTTPFile\UPLOADEDFILE_DOES_NOT_EXIST, eZHTTPFile\UPLOADEDFILE_EXCEEDS_MAX_SIZE, eZHTTPFile\UPLOADEDFILE_EXCEEDS_PHP_LIMIT, eZHTTPFile\UPLOADEDFILE_MISSING_TMP_DIR, eZHTTPFile\UPLOADEDFILE_OK, and eZHTTPFile\UPLOADEDFILE_UNKNOWN_ERROR.

Referenced by handleUpload().

## ◆ findHandler()

eZContentUpload::findHandler | ( | & | $result,
|  |  | $mimeInfo
| ) |  |

Finds the correct upload handler for the file specified in $mimeInfo. If no handler is found it will return the default attribute based handler eZContentUpload, this means that the file is passed to one suitable attribute and handled from there.

Returns
  An object with the interface eZContentUploadHandler or `false` if an error occured. Will return `true` if there is no handler configured for this type.

Definition at line 1367 of file ezcontentupload.php.

References eZExtension\activeExtensions(), eZExtension\baseDirectory(), ezpI18n\tr(), and eZDebug\writeError().

Referenced by handleLocalFile(), and handleUpload().

## ◆ findHTTPFileAttribute()

eZContentUpload::findHTTPFileAttribute | ( |  | $dataMap,
|  |  | $fileAttribute
| ) |  |
| static private

Checks if the attribute with the identifier $fileAttribute in $dataMap supports HTTP file uploading. If not it will go trough all attributes and find the first that has this support.

Returns
  The identifier of the matched attribute or `false` if none were found.

Parameters

  $dataMap | Associative array with class attributes, the key is attribute identifier
  $fileAttribute | The identifier of the attribute that is expected to have the file datatype.

Definition at line 920 of file ezcontentupload.php.

Referenced by handleUpload().

## ◆ findRegularFileAttribute()

eZContentUpload::findRegularFileAttribute | ( |  | $dataMap,
|  |  | $fileAttribute
| ) |  |
| static private

Checks if the attribute with the identifier $fileAttribute in $dataMap supports file uploading. If not it will go trough all attributes and find the first that has this support.

Returns
  The identifier of the matched attribute or `false` if none were found.

Parameters

  $dataMap | Associative array with class attributes, the key is attribute identifier
  $fileAttribute | The identifier of the attribute that is expected to have the file datatype.

Definition at line 953 of file ezcontentupload.php.

Referenced by handleLocalFile(), and objectFileInfo().

## ◆ findStringAttribute()

eZContentUpload::findStringAttribute | ( |  | $dataMap,
|  |  | $nameAttribute
| ) |  |
| static private

Checks if the attribute with the identifier $nameAttribute in $dataMap supports string insertion. If not it will go trough all attributes and find the first that has this support.

Returns
  The identifier of the matched attribute or `false` if none were found.

Parameters

  $dataMap | Associative array with class attributes, the key is attribute identifier
  $nameAttribute | The identifier of the attribute that is expected to have the string datatype.

Definition at line 986 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

## ◆ handleLocalFile()

eZContentUpload::handleLocalFile | ( | & | $result,
|  |  | $filePath,
|  |  | $location,
|  |  | $existingNode,
|  |  | $nameString = `''`,
|  |  | $localeCode = `false`
| ) |  |

Fetches the local file, figures out its MIME-type and creates the proper content object out of it.

Parameters

  array | $result | Result data, will be filled with information which the client can examine, contains: errors An array with errors, each element is an array with a 'description' entry containing the text
  string | $filePath | Path to file which should be stored
  mixed | $location | The node ID which the new object will be placed or the string 'auto' for automatic placement of type.
  eZContentObjectTreeNode | false | $existingNode | Pass a contentobjecttreenode object to let the uploading be done to an existing object, if not it will create one from scratch.
  string | $nameString | The name of the new object/new version
  string | false | $localeCode | Locale code (eg eng-GB, fre-FR, ...) to use when creating the object or the version.

Returns
  boolean

Definition at line 228 of file ezcontentupload.php.

References eZContentObject\defaultLanguage(), detectClassIdentifier(), detectLocations(), eZContentClass\fetchByIdentifier(), eZMimeType\findByFileContents(), findHandler(), findRegularFileAttribute(), findStringAttribute(), processNamePattern(), publishObject(), STATUS_PERMISSION_DENIED, and ezpI18n\tr().

## ◆ handleUpload()

eZContentUpload::handleUpload | ( | & | $result,
|  |  | $httpFileIdentifier,
|  |  | $location,
|  |  | $existingNode,
|  |  | $nameString = `''`,
|  |  | $localeCode = `false`,
|  |  | $publish = `true`
| ) |  |

Fetches the uploaded file, figures out its MIME-type and creates the proper content object out of it.

Parameters

  array | $result | Result data, will be filled with information which the client can examine, contains: errors An array with errors, each element is an array with a 'description' entry containing the text
  string | $httpFileIdentifier | The HTTP identifier of the uploaded file, this must match the name of the input tag.
  mixed | $location | The node ID which the new object will be placed or the string 'auto' for automatic placement of type.
  eZContentObjectTreeNode | false | $existingNode | Pass a contentobjecttreenode object to let the uploading be done to an existing object, if not it will create one from scratch.
  string | $nameString | The name of the new object/new version
  string | false | $localeCode | Locale code (eg eng-GB, fre-FR, ...) to use when creating the object or the version.
  boolean | $publish | whether to publish the new created content object

Returns
  boolean

Definition at line 480 of file ezcontentupload.php.

References eZContentObject\defaultLanguage(), detectClassIdentifier(), detectLocations(), eZContentClass\fetchByIdentifier(), fetchHTTPFile(), findHandler(), findHTTPFileAttribute(), findStringAttribute(), eZDB\instance(), processNamePattern(), publishObject(), setResult(), STATUS_PERMISSION_DENIED, and ezpI18n\tr().

## ◆ hasAttribute()

eZContentUpload::hasAttribute | ( |  | $attributeName | ) |

Returns
  true if the attribute name $attributeName is among the upload parameters.

Definition at line 94 of file ezcontentupload.php.

Referenced by detectLocations().

## ◆ nodeAliasID()

eZContentUpload::nodeAliasID | ( |  | $nodeName | ) |
| static

Returns
  the node ID for the node alias $nodeName or `false` if no ID could be found.

Definition at line 1262 of file ezcontentupload.php.

References eZContentObjectTreeNode\fetch(), eZContentObjectTreeNode\fetchByURLPath(), STATUS_PERMISSION_DENIED, and ezpI18n\tr().

Referenced by detectLocations(), and upload().

## ◆ objectFileInfo()

eZContentUpload::objectFileInfo | ( |  | $contentObject | ) |

Finds the file attribute for object $contentObject and tries to extract file information using eZDataType::storedFileInformation().

Returns
  The information structure or `false` if it fails somehow.

Definition at line 838 of file ezcontentupload.php.

References findRegularFileAttribute().

## ◆ processNamePattern()

eZContentUpload::processNamePattern | ( |  | $variables,
|  |  | $namePattern
| ) |  |
| static private

Parses the name pattern $namePattern and replaces any variables found in $variables with the variable value.

Returns
  The resulting string with all tags replaced.

Parameters

  $variables | An associative array where the key is variable name and element the variable value.
  $namePattern | A string containing of plain text or tags, each tag is enclosed in < and > and defines name of the variable to lookup.

$vars = array( 'name' => 'A name',
'filename' => 'myfile.txt' );
$name = $this->parseNamePattern( $vars, '<name> - <filename>' );
print( $name ); // Will output 'A name - myfile.txt'

Definition at line 1211 of file ezcontentupload.php.

Referenced by handleLocalFile(), and handleUpload().

## ◆ publishObject()

eZContentUpload::publishObject | ( | & | $result,
|  | & | $errors,
|  | & | $notices,
|  |  | $object,
|  |  | $publishVersion,
|  |  | $class,
|  |  | $parentNodes,
|  |  | $parentMainNode
| ) |  |
| private

Publishes the object to the selected locations.

Returns
  `true` if everything was OK, `false` if something failed.

Definition at line 770 of file ezcontentupload.php.

References eZOperationHandler\execute(), eZContentObject\fetch(), setResult(), eZModuleOperationInfo\STATUS_CANCELLED, eZModuleOperationInfo\STATUS_CONTINUE, eZModuleOperationInfo\STATUS_HALTED, and ezpI18n\tr().

Referenced by handleLocalFile(), and handleUpload().

## ◆ result()

static eZContentUpload::result | ( |  | $actionName,
|  |  | $cleanup = `true`
| ) |  |
| static

Returns
  the result of the previous upload operation or `false` if no result was found. It uses the action name $actionName to determine which result to look for.

Parameters

  $cleanup | If `true` it the persisten data is cleaned up by calling cleanup().

Definition at line 1320 of file ezcontentupload.php.

References cleanup(), and eZContentUpload().

## ◆ setResult()

eZContentUpload::setResult | ( |  | $result | ) |

Sets the result array to $result and stores the session variable.

Definition at line 1307 of file ezcontentupload.php.

References eZHTTPTool\instance().

Referenced by handleUpload(), and publishObject().

## ◆ upload()

static eZContentUpload::upload | ( |  | $parameters = `array()`,
|  |  | $module
| ) |  |
| static

Sets some session data taken from $parameters and start the upload module by redirecting to it using $module. Most data will be automatically derived from the `action_name` value taken from settings/upload.ini, other values will override default values.

Definition at line 119 of file ezcontentupload.php.

References eZHTTPTool\instance(), and nodeAliasID().

## Member Data Documentation

## ◆ $Parameters

eZContentUpload::$Parameters = false

The upload parameters.

Definition at line 1424 of file ezcontentupload.php.

## ◆ STATUS_PERMISSION_DENIED

const eZContentUpload::STATUS_PERMISSION_DENIED = 1

Definition at line 51 of file ezcontentupload.php.

Referenced by handleLocalFile(), handleUpload(), and nodeAliasID().

The documentation for this class was generated from the following file:

- ezcontentupload.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.