API: Get item pathname from item ID?

Phrustrated

Joined: 2011-05-23
Posts: 5
Posted: Thu, 2011-05-26 20:23

I've checked through the API documentation but I can't seem to find a function to do this...

I need a function to determine the filesystem path to a gallery item specified by its gallery ID. Either the absolute path or the path relative to the gallery2 base directory, either will do.

Some such functionality must surely exist for gallery2 itself to be able to find the images, but I can't find any documentation about it. Am I just being blind? If there is any documentation a link would be appreciated.

Thanks :)

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Thu, 2011-05-26 20:47

retrieving the id from the url g2_itemId=xxx

/* item */
$itemId = GalleryUtilities::getRequestVariables('itemId');
list($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId, 'GalleryItem');
if ($ret) {
    print 'Error loading item: '.$ret->getAsHtml();
    exit;
}
/* path */
list($ret, $itemPath) = $item->fetchPath();
if ($ret) {
    print 'Error fetching item path: '.$ret->getAsHtml();
    exit;
}

a good example of usage in my zipAlbum script.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
Phrustrated

Joined: 2011-05-23
Posts: 5
Posted: Thu, 2011-05-26 21:17

You lifesaver. Brilliant. Thanks :)