Attachments in extensions

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3862
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Attachments in extensions

Post by Kailey »

Was wondering if someone could post a guide on how to add the attachments feature to an extension. So far all I've done is make an attachment table in a migration.

Code: Select all

$this->table_prefix . 'trackers_attachments'		=> [
	'COLUMNS'		=> [
		'attach_id'				=> ['UINT', null, 'auto_increment'],
		'post_msg_id'			=> ['UINT', 0],
		'ticket_id'				=> ['UINT', 0],
		'in_message'			=> ['BOOL', 0],
		'poster_id'				=> ['UINT', 0],
		'is_orphan'				=> ['BOOL', 1],
		'physical_filename'		=> ['VCHAR:255', ''],
		'real_filename'			=> ['VCHAR:255', ''],
		'download_count'		=> ['UINT', 0],
		'attach_comment'		=> ['TEXT_UNI', ''],
		'extension'				=> ['VCHAR:100', ''],
		'mimetype'				=> ['VCHAR:100', ''],
		'filesize'				=> ['UINT', 0],
		'filetime'				=> ['TIMESTAMP', 0],
		'thumbnail'				=> ['BOOL', 0],
	],
	'PRIMARY_KEY'	=> 'attach_id',
	'KEYS'			=> [
		'filetime'				=> ['INDEX', 'filetime'],
		'post_msg_id'			=> ['INDEX', 'post_msg_id'],
		'ticket_id'				=> ['INDEX', 'ticket_id'],
		'poster_id'				=> ['INDEX', 'poster_id'],
		'is_orphan'				=> ['INDEX', 'is_orphan'],
	],
],
After this, I'm lost as to what service(s) to include and how the code for the form should look so that the file gets added to the DB and to the /files/ directory in my extension.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
Toxyy
Registered User
Posts: 961
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek

Re: Attachments in extensions

Post by Toxyy »

Looks like that's done around here in the parse_attachments function of the message parser using attachment manager:
https://github.com/phpbb/phpbb/blob/2af ... .php#L1514
https://github.com/phpbb/phpbb/blob/2af ... .php#L1659

Which is used around here in posting.php:
https://github.com/phpbb/phpbb/blob/2af ... .php#L1716

But according to how attachments are dealt with in posting.php there is probably a lot more to it, but maybe this will give you a start (or someone who knows more will come along with a better answer :) )
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

Some of my extensions:
[3.3][BETA] Post Form Templates || [3.3][BETA] Anonymous Posts || [3.2][3.3][BETA] ACP Merge Child Forums || [3.2][BETA] Sticky Ad || [3.2][DEV] User Delete Topics || [3.3][DEV] Moderate While Searching || [3.3][RC] Short Number Twig Extension
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 6757
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James

Re: Attachments in extensions

Post by HiFiKabin »

Its marked as abandoned, but Image Upload by DMZX might be useful reading. Also available on DMZX's own website
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3862
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: Attachments in extensions

Post by Kailey »

Thanks for the responses all!
Toxyy wrote: Thu Jul 25, 2024 2:22 am there is probably a lot more to it, but maybe this will give you a start (or someone who knows more will come along with a better answer :) )
There's a lot more, but it's above my head.
HiFiKabin wrote: Thu Jul 25, 2024 8:04 am Image Upload
That helps for images, but doesn't handle all attachments. I was hoping for a more comprehensive guide using phpBB's own functions as opposed to re-writing the classes.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 6757
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James

Re: Attachments in extensions

Post by HiFiKabin »

Kailey wrote: Thu Jul 25, 2024 5:51 pm but doesn't handle all attachments.
*slaps forehead* of course it doesn't. Just ignore me :lol:
User avatar
SpIdErPiGgY
Registered User
Posts: 266
Joined: Sun May 02, 2021 2:11 pm
Location: Erpe-Mere, Aalst, BE
Name: Andy Dm

Re: Attachments in extensions

Post by SpIdErPiGgY »

phpBB NL Extension translations, also on request.
--> Click Here: Myarea51secrets.com <--

Return to “Extension Writers Discussion”