Adding an image from a php script

Author Message

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.

 

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 15:18:55
Script start
Timing: Jan 18 2025 15:18:55
Module start 'layout'
Timing: Jan 18 2025 15:18:55
Module start 'content'
Timing: Jan 18 2025 15:18:56
Module end 'content'
Timing: Jan 18 2025 15:18:56
Script end

Main resources:

Total runtime0.7274 sec
Peak memory usage4,096.0000 KB
Database Queries46

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 587.9219152.6250
Module start 'layout' 0.00500.0035 740.546939.4609
Module start 'content' 0.00850.7172 780.0078408.8281
Module end 'content' 0.72570.0016 1,188.83598.3125
Script end 0.7273  1,197.1484 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4588160.0002
Check MTime0.00140.1900160.0001
Mysql Total
Database connection0.00070.092010.0007
Mysqli_queries0.690494.9242460.0150
Looping result0.00050.0621440.0000
Template Total0.698296.020.3491
Template load0.00210.285420.0010
Template processing0.696195.702420.3480
Template load and register function0.00030.044510.0003
states
state_id_array0.00100.131110.0010
state_identifier_array0.00160.226620.0008
Override
Cache load0.00170.2299140.0001
Sytem overhead
Fetch class attribute can translate value0.00040.058610.0004
Fetch class attribute name0.00140.195810.0014
XML
Image XML parsing0.00010.015310.0001
class_abstraction
Instantiating content class attribute0.00000.001010.0000
General
dbfile0.00060.0887100.0001
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 9
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs