External Upload Form with addItemToAlbum function not working

ernestovargas

Joined: 2006-11-06
Posts: 1
Posted: Mon, 2006-11-06 21:43

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; }
?>

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2006-11-07 22:35

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?

 
Dekken

Joined: 2009-07-23
Posts: 1
Posted: Thu, 2009-07-23 18:46

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.

Quote:
$ret = GalleryEmbed::init(array('fullInit' => true, 'baseUri' => '/photos.php', 'g2Uri' => '/', 'loginRedirect' => '/default.php', 'activeUserId' => 'admin'));
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($albumId);
$filePath = "C:/image.jpg"; //the path to the file on the local disk
$itemName = "image.jpg"; //the name of the new item
$title = "title"; //the title of the new item
$summary = "summary"; //the summary of the new item
$description= "description"; //the description of the new item
list ($base, $mimeType) = GalleryCoreApi::getMimeType($itemName);
list ($ret, $album_item) = GalleryCoreApi::addItemToAlbum($filePath,$itemName,$title,$summary,$description,$mimeType,$albumId);
if ($ret)
{
echo '<BR>ERROR - did NOT add item: <BR>'.$ret->getAsText()."<BR>";
}
$ret = GalleryCoreApi::releaseAllLocks();
if ($ret)
{
echo 'ERROR releasing locks: '.$ret->getAsText()."<BR>";
}
$ret = GalleryEmbed::done();
if ($ret)
{
echo 'ERROR finishing: '.$ret->getAsText()."<BR>";
}

Quote:
Error (ERROR_MISSING_OBJECT) : Missing object for 0

* in modules\core\classes\GalleryStorage\GalleryStorageExtras.class at line 2054 (GalleryCoreApi::error)
* in modules\core\classes\GalleryStorage\GalleryStorageExtras.class at line 98 (GalleryStorageExtras::_identifyEntities)
* in modules\core\classes\GalleryStorage.class at line 313 (GalleryStorageExtras::loadEntities)
* in modules\core\classes\helpers\GalleryEntityHelper_simple.class at line 71 (GalleryStorage::loadEntities)
* in modules\core\classes\GalleryCoreApi.class at line 2361 (GalleryEntityHelper_simple::loadEntitiesById)
* in modules\core\classes\GalleryTheme.class at line 1291 (GalleryCoreApi::loadEntitiesById)
* in themes\matrix\theme.inc at line 65 (GalleryTheme::loadCommonTemplateData)
* in modules\core\classes\GalleryTheme.class at line 932 (MatrixTheme::showAlbumPage)
* in modules\core\classes\GalleryView.class at line 301 (GalleryTheme::loadTemplate)
* in main.php at line 465 (GalleryView::doLoadTemplate)
* in main.php at line 104
* in main.php at line 88

If anyone could spare a moment it'd be great thanks. :)