Saturday, December 29, 2007

phpBB3 Allowed Attachments List MOD

A quick MOD for the phpBB3 posting form to display the allowed file extensions & filesizes for attachments.

MOD should take less than 5 minutes to do manually.
Files to edit are
posting.php
styles/prosilver/template/posting_attach_body.html

If a filesize has been explicitly set for a file type through the ACP it will use that value. If that value has been left at zero to denote no limit, it will use the servers' uploaded file size limit instead.



NOTE: Don't forget to Purge Cache via the ACP after making these file edits.

----[ OPEN ]----
styles/prosilver/template/posting_attach_body.html

----[ FIND ]----
<p>{L_ADD_ATTACHMENT_EXPLAIN}</p>
----[ AFTER ADD ]----

<p>{L_ALLOWED} {L_EXTENSION}:<!-- BEGIN allowed_extension --><!-- IF not allowed_extension.FIRST -->,<!-- ENDIF --> <acronym style="cursor:help;" title="{L_ALLOWED} {L_FILESIZE}: {allowed_extension.FILESIZE} {L_KB}">{allowed_extension.EXTENSION}</acronym><!-- END allowed_extension --></p>

----[ OPEN ]----
posting.php

----[ FIND ]----
// Attachment entry
----[ BEFORE ADD ]----
// Allowed extension list
$allowed_extensions = $cache->obtain_attach_extensions($forum_id);
unset($allowed_extensions['_allowed_']);
ksort($allowed_extensions);
$first_extension = true;
foreach($allowed_extensions as $ext => $vals)
{
if($vals['max_filesize'] == 0)
{
$vals['max_filesize'] = min(
eval('return ' . str_replace(array('k','m','g'), array('*1024','*1048576','*1073741824'), strtolower(trim(ini_get('upload_max_filesize')))) . ';'),
eval('return ' . str_replace(array('k','m','g'), array('*1024','*1048576','*1073741824'), strtolower(trim(ini_get('post_max_size')))) . ';')
);
}
$template->assign_block_vars('allowed_extension', array(
'FILESIZE' => number_format($vals['max_filesize'] / 1024, 2),
'EXTENSION' => $ext,
'FIRST' => $first_extension)
);
$first_extension = false;
}

----[ OPEN ]----
includes/ucp/ucp_pm.php

----[ FIND ]----
global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config

----[ AFTER ADD ]----
, $cache

----[ FIND ]----
compose_pm($id, $mode, $action);

----[ AFTER ADD]----

// Allowed extension list
$allowed_extensions = $cache->obtain_attach_extensions(false);
unset($allowed_extensions['_allowed_']);
ksort($allowed_extensions);
$first_extension = true;
foreach($allowed_extensions as $ext => $vals)
{
if($vals['max_filesize'] == 0)
{
$vals['max_filesize'] = min(
eval('return ' . str_replace(array('k','m','g'), array('*1024','*1048576','*1073741824'), strtolower(trim(ini_get('upload_max_filesize')))) . ';'),
eval('return ' . str_replace(array('k','m','g'), array('*1024','*1048576','*1073741824'), strtolower(trim(ini_get('post_max_size')))) . ';')
);
}
$template->assign_block_vars('allowed_extension', array(
'FILESIZE' => number_format($vals['max_filesize'] / 1024, 2),
'EXTENSION' => $ext,
'FIRST' => $first_extension)
);
$first_extension = false;
}

----[ SAVE/CLOSE ALL FILES ]----
EoM

13 comments:

Harsh@Coding said...

thanks, a lot i got an idea regarding how to make attachment ito post form. but can u explain me why the file extension are not shown at front end in my site

Joe said...

I don't quite understand what you mean H@C.

Alex said...

I did the changes, no effect for me too

Joe said...

Are you using the default template, or a custom one ?

If you're using a custom template, you'll need to edit that templates' "posting_attach_body.html" file instead of the prosilver one.

Alex said...

I edited the template, does not work

Alex said...

Default edited not working

Joe said...

Well that's odd.
Maybe something changed in a recent release oh phpBB3. I'll look into it on a vanilla board this evening.

Shai said...

Not working for me etiher. I'm using phpbb3 and prosilver. I've double checked the source and nothing.

Joe said...

I just installed this on a brand new phpBB3 board and it worked just fine.

I had to "purge cache" via the ACP before it showed up though, which might be what's going on with you guys.

Shai said...

Thanks JOE!!!! Your a life saver.

As Joe said, under the general tab run purge cache.

Fixed my problem!!!

Joe said...

Updated to work when composing a PM as well.

Existing installations only need to apply the last two additions in the instructions to "ucp_pm.php" to be up to date.

Garebooo said...

Great MOD My Friend !

Just test it and it word perfect

Joe said...

Looks like someone finally got around to packaging a proper MOD for this functionality.

http://www.phpbb.com/customise/db/mod/display_allowed_extensions/