Nicolas R
|
Wednesday 18 February 2009 1:31:49 am
Hello,
I try to add an image in the media library from a script but I don't know how to do it. My code is as follow:
$node = eZFunctionHandler::execute( 'content', 'node', array( 'node_id' => $_ParentNodeID ) );
$media = eZContentObject::createWithNodeAssignment( $node, 5, 'fre-FR', false );
$currentVersion = eZContentObjectVersion::fetchVersion( $media->attribute('current_version'), $media->attribute('id') );
$contentObjectDataMap = $media->dataMap();
$contentObjectDataMap['name']->setContent( $fileInfo['basename'] );
$contentObjectDataMap['name']->setAttribute( 'data_text', $fileInfo['basename'] );
$contentObjectDataMap['name']->store();
$contentObjectDataMap['image']->setContent( $pathToImage );
$contentObjectDataMap['image']->setAttribute( 'data_text', $pathToImage );
$contentObjectDataMap['image']->store();
$media->store();
$operationResult = eZOperationHandler::execute( 'content', 'publish', array ('object_id' => $media->attribute('id'),
'version' => $currentVersion->attribute('version')));
This code works for objects of my own classes.
When executing the code, the error is :
Fatal error: Call to a member function httpFile() on a non-object in C:\wamp\www\ezpub401\kernel\classes\datatypes\ezimage\ezimagetype.php o n line 246 In fact, the ['image']->setContent() of the data map seems to expect an object instead of a string but I don't know which object and how to use it. Thank you for any help.
|