Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-15-2009, 04:29 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Trying to understand the album picture data manager

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):
PHP Code:
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(), $vbulletinERRTYPE_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 [DATE]1237162711[/DATE] at [TIME]1237162711[/TIME] ---------------

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

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

PHP Code:
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(), $vbulletinERRTYPE_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
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:27 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03987 seconds
  • Memory Usage 2,325KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete