I am need to have an external form to upload the picture. For that reason I create an external PHP script that add the photo using GalleryCoreApi::addItemToAlbum function, BUT it does not work and it does not return any error messages either. Gallery 2.1 with PHP 5.1.
HERE IS THE CODE...
<?
$itemName = 'Upload Test';
$title = 'Title';
$summary = 'Summary';
$description = 'Description';
$fileName = '/luna.jpg';
$AlbumId = '1669';
require_once('./embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true, 'baseUri' => '/photos.php', 'g2Uri' => '/', 'loginRedirect' => '/default.php', 'activeUserId' => 'jsmith'));
list ($base, $mimeType) = GalleryCoreApi::getMimeType($fileName);
list ($base, $extension) = GalleryUtilities::getFileNameComponents($fileName);
list ($ret, $gfalbum) = GalleryCoreApi::loadEntitiesById($AlbumId);
GalleryCoreApi::acquireWriteLock($AlbumId);
list ($ret, $newImg) = GalleryCoreApi::addItemToAlbum($fileName,
$itemName,
$title,
$summary,
$description,
$mimeType,
$AlbumId,
FALSE);
if ($ret) { echo 'AddItem ' . $ret->getAsText(); exit; }
list($ret,$newImg) = GalleryCoreApi::loadEntitiesById($newImg->getId());
if ($ret) { echo 'loadEntitiesById ' .$ret->getAsText(); exit; }
$ret = GalleryCoreApi::releaseLocks($AlbumId);
if ($ret) { echo 'releaseLocks ' .$ret->getAsText(); exit; }
?>
Posts: 32509
you also need to check $ret from GalleryEmbed::init.
and your use of acquire / release lockId is wrong. lockIds are not the same as item ids.
finally, add a $ret = GalleryEmbed::done(); at the end.
and are you sure your filepath is starting with / ? is it really in the root of the filesystem?
Posts: 1
Hello
I'm having an issue with the addItemToAlbum function.
I've been able to add an item to an album of my choosing, but once it's added, gallery2 seems to dislike it, and causes an error when entering the album which an item was uploaded into.
If anyone could spare a moment it'd be great thanks.