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

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-20-2010, 11:03 AM
billrini billrini is offline
 
Join Date: Aug 2009
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Manually Moving Images/Attachments in VB 4.0.6

I'm stuck at the moment and maybe someone can point me in the right direction. I have a large number of users to migrate from another system to vB. Only problem is that we used a different image gallery for attachments. Everything is 100% images so no docs or other files types.

So, here's what I did as a test run. I set up an album using the vB. I uploaded a few photos. Everything works fine.

I have my settings to store on the filesystem so I can go in and look at the images.

Then I went into filedata and created an entry for the attach and thumb images I was going to move over.

I used that to create entries in the attachment and attachementcategoryuser tables. For most of the stuff I just used the same settings that were in all of my other uploads. Obviously filename, sizes, hashes, etc. I made specific to the imported test files.

Lastly, I updated the album table to reflect the added pic in "visible".

Then I moved the two files into the /attachements/1 and changed them to 45.attach and 45.thumb (these correspond to the attachmentid in attachment).

When I go to my album I see a broken image. I experimented around a bit with renaming some of the filenames and when I rename an image that was working to 45.attach and 45.thumb they don't work. But I can take the files that I imported manually and rename them 37.attach and 37.thumb and the manually uploaded files show up.

I've checked all the permissions and such and can't find a reason why they're not showing up.

Anything I'm missing here? Is there another table that needs modified? Or even if anybody knows which exact file has the call to create these database fields when a new file is uploaded. I can't seem to find any of the inserts.

Edit: I should say in the filedata set, I didn't create two records. But it asks for information about both the original and the thumb in that table so I described it that way to make it clearer that I filled in all of the information. Funny how trying to be more clear you make yourself less clear :-)

--------------- Added [DATE]1285050715[/DATE] at [TIME]1285050715[/TIME] ---------------

I didn't get a response :-( so I ended up figuring it out on my own and thought I would share in case anybody else has to do something like this.

How to import external images as attachments into vB 4.0.x

First, get the basic information about the file. Get the height, width, file size of both the thumbnail and the original pic. You will also need the md5 hash value of the original. In PHP that's rather easy:

PHP Code:
$filehash file_get_contents('YOUR FILE');
$hash_val md5($filehash); 
You could shorten that to one line:

PHP Code:
$hash_val md5(file_get_contents('YOUR FILE')); 
But I put it as two lines to make it easier to figure out what you're doing.

Once you have that data about your file you're going to need to update the filedata table to tell vB about the new file.

The fields in filedata are:

filedataid = auto incremented so you can leave blank

userid = the userid of the album owner

dateline = unix timestamp

thumbnail_dateline = you can either use the same value as dateline or get the actual unix timestamp value for the file. I don't think it matters since I don't believe there is any check against last modified timestamp.

filedata = BLOB data type. I believe this is where the actual image data is stored IF the files are stored in the db. If you're storing to the filesystem of your computer this will have no value.

filesize = file size of your main file. you can get this by doing "ls -la" (Linux/Unix) on the file.

filehash = the file hash value you got with the md5 routine above

thumbnail = I believe this is just like the filedata field. if you were storing this in the database this is where they would store the thumbnail. again, just leave it empty.

thumbnail_filesize = file size of the thumbnail. see filesize above.

extension = this is the original format of your file. since vB will be storing your file like 45.attach rather than 45.attach.jpg you have to tell vB what format headers to send back to the browser so it can be rendered properly. Fortunately for me, all of mine are jpg

refcount = not sure what it is but set it to 1 (that's what all my other attachments are set to)

width = the width of your main image

height = the height of your main image

thumbnail_width = self explanatory

thumbnail_height = self explanatory

Once you've updated the table you need the filedataid which was auto incremented when you created the entry in the database. Let's say for example it's 49. You will use that in other references in the database and this will be the filename you assign your files.

For example:

49.attach
49.thumb

Next you go to the table attachmentcategoryuser and create a record there

filedataid = the filedata id we just got from the previous table insert

userid = the userid of the album/picture owner

categoryid = not sure what this is but everything in my database, including the images that came preloaded as sample data is set to 0 so that seems to be a pretty safe value to put there.

filename = I'm not sure if this is important because you lose the filename when you rename the files anyway. But I just use the original name of the image that I'm importing to be on the safe side.

dateline = unix timestamp. I just use the same unix timestamp across all of the dateline entries assuming that if this were a program executing that it could make three table inserts in under 1 second.

Next you need to update attachment

attachmentid = this is an auto incremented value. The mistake I made and was asking about in my OP was that I thought this was the value I needed to change my image to. It's not.

contenttypeid = not totally sure what this value is but everything in my albums is set to 8. So I set it to 8

contentid = this seems to to be the album ID. whatever album you're inserting into this should be the album id of that album.

userid = user id of the owner of the pic

dateline = self explanatory

filedataid = this is your filedataid that you got from inserting the record into filedata

state = set to visible if you want the image to appear in the album.

counter = set to 0

posthash = none of my profile pics has a value so I just leave this blank.

filename = same as the insert into attachmentcategoryuser

caption = you can set the caption for the photo here. i usually leave blank because there was no caption capability in the system I was importing from.

reportthreadid = not sure what this is but everything in my db is set to 0 so 0 seems like a safe value

settings = again, not sure what it is but everything in my db is set to NULL so setting it to NULL seems like a safe way to go.

displayorder = yet again, not sure what this does but everything in my db is set to 0 . . .

Now, go and rename your files to the filedataid. 49.attach and 49.thumb and they should appear in the album for that user.

WARNING!!!

As I've indicated in my comments above, I don't 100% understand how vB does the attachments. Through trial and error, checking out various parts of the vB code, etc I found a solution that allowed me to do what I wanted.

It would be nice if this was somehow documented somewhere but it's not. I'm simply sharing what worked for me since I spent several hours banging my head against a wall trying to find a solution.

That being said, I take no responsibility and am not supporting this in any way. I have 65,000 users to import into vB and several hundred thousand pictures from my legacy site. If I notice that any of my above information is incorrect I will update it. But I'm probably about a month or two away from my final import so . . . use at your own risk.
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:40 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03411 seconds
  • Memory Usage 2,282KB
  • Queries Executed 12 (?)
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_postinfo_query
  • fetch_postinfo
  • 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