eZ Community » Forums » Developer » Can't create IMAGE programmatically
expandshrink

Can't create IMAGE programmatically

Can't create IMAGE programmatically

Thursday 20 December 2012 1:14:51 am - 6 replies

I tried to follow the guide below to create and publish an Image:
http://share.ez.no/learn/ez-publi...g-ez-publish-objects-in-php/(page)/8
Image is created with all text data except the "image" attribute, that is the image file uploader via CMS.

I Use ezpublish 4.6

Thursday 20 December 2012 1:00:26 pm

can you paste here your code?

Thursday 20 December 2012 2:44:17 pm

// getting information required to setup the node:

$user = eZUser::fetchByName( 'admin' ); //import our user (replace with the code for the previous step if necessary)

if ( !$user )

{

    //if no user exists let's pull out the current user:

    $user = eZUser::currentUser();

}

$parent_node = eZContentObjectTreeNode::fetch( 191 );

 

//setting node details

$params = array();

$params['class_identifier'] = 'image';

$params['creator_id'] = $user->attribute( 'contentobject_id' ); //using the user extracted above

$params['parent_node_id'] = $parent_node->attribute( 'node_id' ); //pulling the node id out of the parent 

$params ['storage_dir' ] = "/var/siteaccess/images/";

//setting attribute values

$attributesData = array ( ) ;

$attributesData['name'] = 'Adding a random image'; 

$attributesData ['image'] = 'ciao.jpg'; 

$params['attributes'] = $attributesData;

//publishing node

$imageObject = eZContentFunctions::createAndPublishObject( $params );

Modified on Thursday 20 December 2012 2:47:05 pm by ruben rizzi

Thursday 20 December 2012 3:12:32 pm

Without digging too much into the code, a workaround: use the fromstring() method of the ezimage datatype.

You can prossibly "patch" the content of the image attribute without having to publish version 2 of the object, but if having one extra version is not a problem I would recommend to call the publication method again after altering the attribute.

ps: did you try using the absolute path to the image file in your code?

Modified on Thursday 20 December 2012 3:13:18 pm by Gaetano Giunta

Thursday 20 December 2012 3:53:39 pm

I tried the absolute path with no success. Now I try the other suggestions of yours, and i let you know, thank you Gaetano!

Modified on Thursday 20 December 2012 3:54:55 pm by ruben rizzi

Thursday 20 December 2012 4:39:26 pm

Solved! The problem was the storage_path:
You have to use the right path of the image file in the filesystem, not an ezPublish relative or absolute path: i used:

$_SERVER['DOCUMENT_ROOT']

such as:
$params ['storage_dir' ] = $_SERVER['DOCUMENT_ROOT']. "/var/siteaccess/images/";

Thanks to:

http://share.ez.no/forums/developer/create-objects-with-ezimage-datatype 

Modified on Thursday 20 December 2012 4:50:08 pm by ruben rizzi

Friday 14 June 2013 4:54:30 am

The reply has been removed because of violation of forum rules.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from