PDA

View Full Version : Trying to understand the album picture data manager


JamesAB
03-15-2009, 04:29 AM
I'd like to add a picture that already exists (not from an upload form) into an album.

Album '2' exists.
/home/testforum/public_html/12.jpg is the full path of the picture I want to add.

This is what I've tried so far (adapted from album.php):
require_once('./global.php');
require_once(DIR . '/includes/class_upload.php');
require_once(DIR . '/includes/class_image.php');
require_once(DIR . '/includes/functions_album.php');

$albuminfo = fetch_albuminfo(2);

$vbulletin->GPC['upload'] = array( 'name' => '12.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/home/testforum/public_html/12.jpg',
'error' => '0',
'size' => '29348' );

$upload = new vB_Upload_AlbumPicture($vbulletin);
$upload->data =& datamanager_init(fetch_picture_dm_name(), $vbulletin, ERRTYPE_STANDARD, 'picture');
$upload->image =& vB_Image::fetch_library($vbulletin);
$upload->albums = array($albuminfo);

$upload->maxwidth = $userinfo['permissions']['albumpicmaxwidth'];
$upload->maxheight = $userinfo['permissions']['albumpicmaxheight'];
$upload->maxuploadsize = $userinfo['permissions']['albumpicmaxsize'];


if (!$pictureid = $upload->process_upload())
{
$errors["$uploadid"] = $upload->fetch_error();
print_r($errors);
}
else
{
$pictureids["$uploadid"] = $pictureid;
}
But I only get an "Upload of file failed." error.

What do I need to do in order to use the datamanager to add a static file rather than a file from an upload form?

Thanks for your help,
James

--------------- Added 1237162711 at 1237162711 ---------------

I was probably wrong to try to 'bend' the upload class to use a static file that already exists. :o

I did some work with the vB_DataManager_Picture class and came up with this:

require_once('./global.php');
require_once(DIR . '/includes/class_upload.php');
require_once(DIR . '/includes/class_image.php');
require_once(DIR . '/includes/functions_album.php');

$albuminfo = fetch_albuminfo(2);
$static_filename = '12.jpg';
$static_file = '/home/testforum/public_html/12.jpg';

$image =& vB_Image::fetch_library($vbulletin);
$thumbnail = $image->fetch_thumbnail($static_filename, $static_file, $vbulletin->options['album_thumbsize'], $vbulletin->options['album_thumbsize'], 80 );
$imageinfo = $image->fetch_image_info($static_file);
$filesize = @filesize($static_file);
$extension = file_extension($static_file);
$caption = $static_filename;

$picturedata =& datamanager_init(fetch_picture_dm_name(), $vbulletin, ERRTYPE_SILENT, 'picture');
$picturedata->setr_info('thumbnail', $thumbnail['filedata']);
$picturedata->setr_info('filedata', file_get_contents($static_file));
$picturedata->set('thumbnail_dateline', TIMENOW);
$picturedata->set('thumbnail_width', $thumbnail['width']);
$picturedata->set('thumbnail_height', $thumbnail['height']);
$picturedata->set('userid', 1);
$picturedata->set('filesize', $filesize);
$picturedata->set('width', $imageinfo['0']);
$picturedata->set('height', $imageinfo['1']);
$picturedata->set('extension', $extension);
$picturedata->set('caption', $caption);
$picturedata->set_info('albums', array($albuminfo));
$picturedata->save();
unset($picturedata);

I'll have to add error checking and the size checks that were only available in the upload class, but this works.

Any suggestions for making this work better or cleaner?

Thanks,
James