Forums / Developer / Get the image storage path from a ContentObjectID (php-side)
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
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
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 ;)