Forums / Developer / Get the image storage path from a ContentObjectID (php-side)

Get the image storage path from a ContentObjectID (php-side)

Author Message

Alexandre Nion

Monday 30 January 2006 6:48:47 am

Hi all,

I'm in a php function and I have the ID of a contentObject which represents an ezImage object. And my problem is that I'd like to know his real storage url but I don't see any simple way to do it, although it shouldn't be so difficult... I mean that when I do:

$myImageObject = eZContentObject :: fetch( 76 );  // where 76 is my contentObjectID
print_r( $myImageObject  );
// displays properties but doesn't display any contained attributes.. don't know why..

// Then I can do:
print_r( $myImageObject->contentObjectAttributes() );
// to display all the object attributes..

Array {
....
    [2] => ezcontentobjectattribute Object
        (
 ...
            [ID] => 266
            [ContentObjectID] => 76
            [Version] => 2
            [LanguageCode] => fre-FR
            [AttributeOriginalID] => 0
            [SortKeyInt] => 0
            [SortKeyString] => 
            [DataTypeString] => ezimage
            [DataText] => <?xml version="1.0" encoding="UTF-8"?>
<ezimage serial_number="1"
         is_valid="1"
         filename="geek.png"
         suffix="png"
         basename="geek"
         dirpath="var/plain/storage/images/media/images/geek/266-2-fre-FR"
         url="var/plain/storage/images/media/images/geek/266-2-fre-FR/geek.png"
         original_filename="alignement_resultats.png"
         mime_type="image/png"
         width="1155"
         height="217"
         alternative_text=""
         alias_key="1293033771"
         timestamp="1138213887">
  <original attribute_id=""
            attribute_version=""
            attribute_language="" />
</ezimage>

            [DataInt] => 
            [DataFloat] => 0
        )
...
}

// Well, now I can see the storage path in the DataText field but I don't know how to access it easily (without having to parse individually, I'd like a generic method..):

So is there a way to get the image storage url easily? (maybe via ezImage or imageHanler, I didn't manage with the objects tried)

Thanx for your lights,
Alexandre

Łukasz Serwatka

Monday 30 January 2006 6:57:59 am

Hi Alexandre,

Use this code to get image URL

objectWithIMG = eZContentObject::fetch( 171 ); 
 
$dataMap =& $objectWithIMG->attribute( 'data_map' ); 
 
$image =& $dataMap['image']->content(); 
 
$list =& $image->aliasList(); 
 
var_dump( $list['original']['url'] );

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Alexandre Nion

Monday 30 January 2006 8:26:21 am

wow thank you Lukasz, this code rocks!
Exactly what I needed, I knew it wasn't so hard in the end ;)

Piotrek Karaś

Wednesday 11 February 2009 10:04:47 pm

Hi guys,

And how do we generate an alias that has not been generated up to the moment of fetching?

For example: I have 20 aliases defined in the website, but the aliasList() method only returns 4 (the underlying XML-base for that method also contains 4 alias entries). How do I force particular alias generation in PHP?

Thanks!

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Piotrek Karaś

Thursday 12 February 2009 12:08:31 am

OK, for those interested and also for verification, this seems to work:

<?php
$targetAliasName = 'my_huge_image';
$contentObjectAttributeID = 1234567...;
$contentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID );
$aliasHandler = new eZImageAliasHandler( $contentObjectAttribute );
$myHugeImageAliasData = $aliasHandler->imageAlias( $targetAliasName );
?>

If the alias entry had not existed, seems to be created automatically (provided it had existed in the image.ini declarations). I hope this includes the internal caching layer ;)

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

eZ debug

Timing: Jan 18 2025 04:21:35
Script start
Timing: Jan 18 2025 04:21:35
Module start 'content'
Timing: Jan 18 2025 04:21:36
Module end 'content'
Timing: Jan 18 2025 04:21:36
Script end

Main resources:

Total runtime1.3724 sec
Peak memory usage4,096.0000 KB
Database Queries202

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 589.0859180.7969
Module start 'content' 0.00621.1834 769.8828618.5078
Module end 'content' 1.18950.1828 1,388.3906341.3359
Script end 1.3723  1,729.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00460.3372210.0002
Check MTime0.00150.1126210.0001
Mysql Total
Database connection0.00080.057110.0008
Mysqli_queries1.272592.72252020.0063
Looping result0.00310.22882000.0000
Template Total1.340497.720.6702
Template load0.00230.170620.0012
Template processing1.338197.501120.6690
Template load and register function0.00030.025410.0003
states
state_id_array0.00110.077110.0011
state_identifier_array0.00150.112220.0008
Override
Cache load0.00170.1246290.0001
Sytem overhead
Fetch class attribute can translate value0.00370.270940.0009
Fetch class attribute name0.00220.158570.0003
XML
Image XML parsing0.00250.182540.0006
class_abstraction
Instantiating content class attribute0.00000.001980.0000
General
dbfile0.00330.2421360.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 23
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs