Firefox PHP

mod: upload attachments in directory, not db

Posted by dissurion 
Re: mod: upload attachments in directory, not db
April 18, 2007 10:17AM
I am new to Phorum and after installing this mod I still get the error message that attached file size limit is 614.4KB. Is there a simple fix for this?

I rather like the files being stored in a directory rather than the database.

I have tried to find the location of the config file that specifies the filesize limitation in my "MySQL" server but cannot seem to locate the setting. And I am ashamed to admit I haven't the foggiest idea where the PHP server settings are either.

Thanks for any help.
Re: mod: upload attachments in directory, not db
April 18, 2007 03:27PM
The php settings are in php.ini
There is also a maximum file setting in phorum administration (in the user settings section in the general settings)
Re: mod: upload attachments in directory, not db
April 18, 2007 03:36PM
the sanity checks in the admin should tell you some more.


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: mod: upload attachments in directory, not db
April 19, 2007 12:34AM
I guess the system would still check the maximum size using the MySQL + PHP limits. The fact that there is a module installed for storing the files on the file system instead of in the database, does not make a difference for the Phorum internals.

Like Thomas suggested, the sanity checks might give you a hunch about what is currently limiting the maximum upload size. Set the upload size for a forum to your desired maximum and run the sanity checks in the admin. It should show a warning, explaining you why the upload size is a problem.

If it's a PHP limit, then you'll have to edit the php.ini to allow bigger uploads. If it's a MySQL limit, then you might have to allow larger packets in MySQL or modify the database layer file include/db/mysql.php to let the max packet function return a large value to trick Phorum into allowing larger files.

Do mind that the fsattachments module is not a finished module and that AFAIK currently none of the developers is using the module themselves.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: mod: upload attachments in directory, not db
April 19, 2007 10:33AM
I appreciate the quick response.

Truly impressive!

I followed the prescribed sanity check procedure and according to Phorum it is my database. I am currently running MySql version 4. I am not proficient at all in configuring MySql so if you could point me in the general direction of the file(s) that I need edit to increase the packet size I would be grateful.

Oh and yes I understand that this mod is still unfinished.

Hey, what's life without risks?
*grins*

The truth is whether I use a directory or the database to hold files I still need to increase the file size if I can. Otherwise I could provide a file splitting utility for use on larger files but that's a step I'd rather avoid if possible.

Anyway, as always, my thanks for any help you can provide.
Re: mod: upload attachments in directory, not db
April 19, 2007 04:43PM
Since it's your database and db configuration isn't the way, you'll have to hack the include/db/mysql.php script for this. It's fairly easy to do. Open the Phorum file include/db/mysql.php in a text editor. Then look for the following block of code:

function phorum_db_maxpacketsize ()
{
    $conn = phorum_db_mysql_connect();
    $res = mysql_query("SELECT @@global.max_allowed_packet",$conn);
    if (!$res) return NULL;
    if (mysql_num_rows($res)) {
        $row = mysql_fetch_array($res);
        return $row[0];
    }
    return NULL;
}

Delete the red code from it, so it will end up like this:

function phorum_db_maxpacketsize ()
{
   return NULL;
}

This will let the atabaes layer report to Phorum that the upload limit cannot be determined. That will effectively ignore the MySQL limits.

Good luck. I hope this will solve your problem.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: The Hack
May 10, 2007 04:30AM
Quote
miles
Quote

Is your hack public(ly available)?
I would be glad to have a look at it...

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.

Tiny something was missing in your code that was

before:

			$dest = attachment_filename($file_id);

			file_put_contents($dest = tempnam('/tmp', 'db_file_save'), base64_decode($buffer));
			
			if (!chmod($dest, 0666))	// if this fails the file is absent
			{
					trigger_error("Couldn't store file $file[name]", E_USER_ERROR); 
			}
			return $file_id;


Should be:

			$dest = attachment_filename($file_id);

			file_put_contents($dest = tempnam('/tmp', 'db_file_save'), base64_decode($buffer));
			
			if (!chmod($dest, 0666))	// if this fails the file is absent
			{
					trigger_error("Couldn't store file $file[name]", E_USER_ERROR); 
			} else {
					copy($dest, attachment_filename($file_id));
			}
			return $file_id;

You copied from the buffer to the /tmp but then forgot to actually copy the file back to your fs-storage.

(I am absolutely no php guru, so forgive me if things are not perfect here, but the given solution works fine for me)
Re: The Hack
May 10, 2007 10:35AM
As a teaser for 5.2:

I wrote a new file API layer for 5.2, which makes it possible to cleanly implement other data storage backends for Phorum. The file contents do never have to be stored in the database, but can be stored to a different backend at write time already (in which case this would be a solution for database servers with low max packet size settings in combination with large attachments). The file storage API uses some clean hooks for this (file_store, file_check_read_access, file_retrieve and file_delete).


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: The Hack
May 10, 2007 08:10PM
Quote
mmakaay
I wrote a new file API layer for 5.2, which ... uses some clean hooks for this (file_store, file_check_read_access, file_retrieve and file_delete).

Man, it's like you're removing a splinter that's been stuck in my foot for two years :D
It's great idea to return files storage in folders instead of MySQL DB! +
August 22, 2007 02:10PM
Quote
mmakaay
As a teaser for 5.2:
I wrote a new file API layer for 5.2, which makes it possible to cleanly implement other data storage backends for Phorum.
Maurice,
It will be great if it will be possible to export files from current DB to folder on server and minimize MySQL DB size. And also to continue store files in attachments folder, instead of DB.

Alexander Medentsev. Moscow. Russia.
Sorry, only registered users may post in this forum.

Click here to login