MyBB Community Forums

Full Version: Attachments stored in BLOB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm on the final step in my custom module for the Merge system. However, I'm unsure how to go about the attachments.

This is my database structure:
	attachment_id	int(10)
	user_id 		int(10)
	file_name 		varchar(255)
	file_type 		varchar(80)
	file_contents 	longblob
	upload_date 	datetime
	finalized 		tinyint(3)
	downloads 	int(10)
	image_width 	smallint(5)
	private 		tinyint(3)

And as you can see, the file itself is stored in a blob field, and there is no entry for the size of the file. How would I go about merging something done this way into the MyBB database? The rest I've got, but my php knowledge is very basic and I've never dealt with blob fields. Thanks in advance.
Oops, as an addendum, obviously there is also no uploads path since the file is blobbed into the database, right?
Correct, you would just take the contents of the blob field and fwrite it into a properly formatted attachment file in the MyBB system. Take a look at the vB module to see an example.
Thanks Ryan. I'll do that this evening, and then post again if I still don't get it. I'm not actually a php developer Wink I'm a C developer, and php is just similar enough that I can muddle by.
Ok, question Smile
Can some explain this to me? I'm assuming it means like the attachment description? The board I'm converting doesn't have that. Is it safe to leave this field of insert_data empty? For now I'm going to comment this out and just put in $isert_data['posthash'] = 'Imported Attachment'; so let me know. Thanks.

if($posthash['posthash'])
		{
			$insert_data['posthash'] = $posthash['posthash'];
		}
		else
		{
			mt_srand((double) microtime() * 1000000);
			$insert_data['posthash'] = md5($posthash['tid'].$posthash['uid'].mt_rand());
		}

Question #2
Is there a way to get the size of a blob field to put into the $insert_data['filesize'], or can MyBB redect the filesize? Or should I add file size from disk checking into the after_insert function? Shoot me your ideas on how to finish this and I'll be done with my merger. Thanks again for the support.
Ok, so reading on the MySQL forums says to use OCTET_LENGTH() to get the blob size. Easy enough. Still appreciate any thoughts on this.
Then again, nothing is ever that simple. Just got an error from OCTET_LENGTH. So I still need to know what the proper way to file size this is.