mod: upload attachments in directory, not db
Posted by dissurion
Re: The Hack March 03, 2006 09:19AM |
Registered: 17 years ago Posts: 34 |
Quote
miles
Sure, here it is. Modified code starts at line 2502, and is bracketed by an if ($USE_FS_ATTACHMENTS=true) {} statement. I left the original code in the else{} branch mainly for reference.
Also, I warn you that I ripped bunch of client-specific stuff out and haven't tested the hack since, which is why I'm posting it informally here and not in the hacks forum.
Thanks a lot! I will look at your alternative approach :-)
P.
Edited 1 time(s). Last edit at 03/05/2006 05:52AM by pcoud.
Re: The Hack March 05, 2006 05:17PM |
Registered: 17 years ago Posts: 34 |
Works very fine :-)
Just some minor points: in phorum_db_file_save, the generation of a temporary filename (in case $dest would be empty?) seems strange (but I may miss something in the understanding). I replaced:
file_put_contents($dest = tempnam('/tmp', 'db_file_save'), base64_decode($buffer));
by:
file_put_contents($dest, base64_decode($buffer));
Also, when the attachments are stored in fs, there are useless base64 encoding/decoding which are taking place. They could be removed (at the cost of not being completely transparent to the code depending on the database layer).
It is nice in your approach to be able to upgrade phorum 3 attachments to phorum 5, keeping them in FS storage.
By the way, there is minor copy&paste typo in the comment of mysql.php (both in the original phorum code and your modified version):
/**
* This function saves a file to the db
*/
should be "deletes" instead of "saves"
P.
Edited 1 time(s). Last edit at 03/05/2006 05:18PM by pcoud.
Just some minor points: in phorum_db_file_save, the generation of a temporary filename (in case $dest would be empty?) seems strange (but I may miss something in the understanding). I replaced:
file_put_contents($dest = tempnam('/tmp', 'db_file_save'), base64_decode($buffer));
by:
file_put_contents($dest, base64_decode($buffer));
Also, when the attachments are stored in fs, there are useless base64 encoding/decoding which are taking place. They could be removed (at the cost of not being completely transparent to the code depending on the database layer).
It is nice in your approach to be able to upgrade phorum 3 attachments to phorum 5, keeping them in FS storage.
By the way, there is minor copy&paste typo in the comment of mysql.php (both in the original phorum code and your modified version):
/**
* This function saves a file to the db
*/
should be "deletes" instead of "saves"
P.
Edited 1 time(s). Last edit at 03/05/2006 05:18PM by pcoud.
Re: The Hack March 05, 2006 05:32PM |
Registered: 17 years ago Posts: 21 |
Quote
pcoud
Just some minor points: in phorum_db_file_save, the generation of a temporary filename (in case $dest would be empty?) seems strange (but I may miss something in the understanding).
You were right to replace it. In my original code, I was assuming the upload to be an image, generating multiple resized versions of it, and throwing away the original. The temporary filename is a leftover from that.
Re: mod: upload attachments in directory, not db April 20, 2006 05:44PM |
Registered: 16 years ago Posts: 3 |
August 15, 2006 06:29PM |
Registered: 15 years ago Posts: 216 |
Two issues mainly:
A) When I delete the file from the forum this module does not delete accordingly the file which is stored in the attachments directory.
B) This module could have been comfortable to me if it allowed a larger file size then the one pre-fixed in the forum's settings.
Any way to overcome to this issue?
Thanks...
A) When I delete the file from the forum this module does not delete accordingly the file which is stored in the attachments directory.
B) This module could have been comfortable to me if it allowed a larger file size then the one pre-fixed in the forum's settings.
Any way to overcome to this issue?
Thanks...
Re: mod: upload attachments in directory, not db August 16, 2006 04:21AM |
Registered: 20 years ago Posts: 1,076 |
August 16, 2006 09:13AM |
Registered: 15 years ago Posts: 216 |
August 16, 2006 09:32AM |
Admin Registered: 17 years ago Posts: 8,532 |
That is the limit that is imposed by either the PHP max upload configuration or the database's maximum package size configuration. Looking at the limit, I think it's the database package size limit.
I do not know the internals of this mod. If it stores the file in the database, prior to storing it on the system, then this limit should be honoured. If this is not the case, the limit could be ignored. Ignoring it is no core feature however. You'd need to hack the Phorum code a bit for that. I think that all you need to do is edit your database layer file (include/db/<layername>.php) and let the function phorum_db_maxpacketsize() return NULL at all cases.
If after this, you run into another limiting problem, it's the configuration of PHP which limits the upload size.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
I do not know the internals of this mod. If it stores the file in the database, prior to storing it on the system, then this limit should be honoured. If this is not the case, the limit could be ignored. Ignoring it is no core feature however. You'd need to hack the Phorum code a bit for that. I think that all you need to do is edit your database layer file (include/db/<layername>.php) and let the function phorum_db_maxpacketsize() return NULL at all cases.
If after this, you run into another limiting problem, it's the configuration of PHP which limits the upload size.
Maurice Makaay
Phorum Development Team



Re: mod: upload attachments in directory, not db October 18, 2006 04:07AM |
Registered: 20 years ago Posts: 80 |
October 18, 2006 05:34AM |
Admin Registered: 17 years ago Posts: 8,532 |
We do not want to build it in the main Phorum code, but there are plans for facilitating implementation of different storage backends. Maybe through hooks or maybe through having a storage layer. At this moment, there are so many development tasks to do, that I do not think plans have fully settled on this.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Sorry, only registered users may post in this forum.