Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: dschwab9 in September 26, 2004, 10:51:06 NACHMITTAGS

Titel: No attachment limit for admins
Beitrag von: dschwab9 in September 26, 2004, 10:51:06 NACHMITTAGS
I would like to be able to have the file size/extension limits not apply to admins.  Is this easy to do?  There's times I need to upload a couple of meg zip or something, but I don't want to give the world access to do that.  I've been changing the limit, uploading the file, then changing it back.
Titel: Re: No attachment limit for admins
Beitrag von: [Unknown] in September 26, 2004, 10:58:13 NACHMITTAGS
Post.php, find:
if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)

Replace:
if (!$user_info['is_admin'] && !empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)

-[Unknown]
Titel: Re: No attachment limit for admins
Beitrag von: dschwab9 in September 26, 2004, 11:10:58 NACHMITTAGS
Perfect!  Thanks
Titel: Re: No attachment limit for admins
Beitrag von: Ben_S in September 27, 2004, 09:47:27 VORMITTAG
This should be in tips and tricks ;).
Titel: Re: No attachment limit for admins
Beitrag von: dschwab9 in September 27, 2004, 05:48:27 NACHMITTAGS
Zitat von: Ben_S in September 27, 2004, 09:47:27 VORMITTAG
This should be in tips and tricks ;).

Well, can you move it there?
Titel: Re: No attachment limit for admins
Beitrag von: Ben_S in September 27, 2004, 05:56:13 NACHMITTAGS
Would if I could, my post was a suggestion for someone with move powers, I dont have them :(.

[edit]
Someone did  ;D
[/edit]
Titel: Re: No attachment limit for admins
Beitrag von: CarLBanks in Oktober 16, 2004, 04:21:34 NACHMITTAGS
I still can't upload anything over 192.
Titel: Re: No attachment limit for admins
Beitrag von: Ben_S in Oktober 17, 2004, 09:56:44 VORMITTAG
Same here, comes back with

Your file is too large. The maximum attachment size allowed is 192 KB.

My max attachment setting is 100KB so dunno where it gets 192 KB from.
Titel: Re: No attachment limit for admins
Beitrag von: [Unknown] in Oktober 17, 2004, 04:02:35 NACHMITTAGS
Maybe it's your per-post limit?

-[Unknown]
Titel: Re: No attachment limit for admins
Beitrag von: Ben_S in Oktober 17, 2004, 07:25:09 NACHMITTAGS
Not sure what you mean by per post limit?
Titel: Re: No attachment limit for admins
Beitrag von: [Unknown] in Oktober 17, 2004, 07:45:41 NACHMITTAGS
Please consult your attachment settings.

-[Unknown]
Titel: Re: No attachment limit for admins
Beitrag von: Ben_S in Oktober 17, 2004, 07:52:26 NACHMITTAGS
Doh, never seen that one before. thats two new things I've learnt today.

Have now set it suitably high, thanks for that.
Titel: Re: No attachment limit for admins
Beitrag von: forumite in Mai 28, 2005, 01:12:07 NACHMITTAGS
Zitat von: [Unknown] in September 26, 2004, 10:58:13 NACHMITTAGS
Post.php, find:

I've just found this topic, so apologies for the late question.

I can find Post.template.php but can't find Post.php  Which sub-directory would it be in?

TIA
Titel: Re: No attachment limit for admins
Beitrag von: [Unknown] in Mai 28, 2005, 01:27:12 NACHMITTAGS
How do I modify files? (http://www.simplemachines.org/community/index.php?topic=24110.0)

-[Unknown]
Titel: Re: No attachment limit for admins
Beitrag von: seammer in Juli 04, 2005, 06:00:36 NACHMITTAGS
I'm watching this topic, as I couldn't find "Post.php" ANYWHERE...

I'm very new to SMF forums... ???
Titel: Re: No attachment limit for admins
Beitrag von: forumite in Juli 05, 2005, 12:53:38 VORMITTAG
Zitat von: seammer in Juli 04, 2005, 06:00:36 NACHMITTAGSI couldn't find "Post.php" ANYWHERE...

It's in your Sources directory.
Titel: Re: No attachment limit for admins
Beitrag von: xenovanis in Juli 05, 2005, 02:03:48 VORMITTAG
Zitat von: seammer in Juli 04, 2005, 06:00:36 NACHMITTAGS
I'm watching this topic, as I couldn't find "Post.php" ANYWHERE...

I'm very new to SMF forums... ???

Post.php is in the folder /Sources
Titel: Re: No attachment limit for admins
Beitrag von: rojamaia in August 27, 2005, 08:23:55 VORMITTAG


i thought that if we should edit it, it should not just be for the over-all attachment limit, but edit more of the code below that, to allow more permissions to the admin.

would this be alright?

// Is the file too big?
if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
fatal_lang_error('smf122', false, array($modSettings['attachmentSizeLimit']));

// Have we reached the maximum number of files we are allowed?
$quantity++;
if (!$user_info['is_admin'] && !empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'])
fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));

// Check the total upload size for this post...
$total_size += $_FILES['attachment']['size'][$n];
if (!$user_info['is_admin'] && !empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
fatal_lang_error('smf122', false, array($modSettings['attachmentPostLimit']));

if (!$user_info['is_admin'] && !empty($modSettings['attachmentCheckExtensions']))
{
if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions']))))
fatal_error($_FILES['attachment']['name'][$n] . '.<br />' . $txt['smf123'] . ' ' . $modSettings['attachmentExtensions'] . '.', false);
}

if (!$user_info['is_admin'] && !empty($modSettings['attachmentDirSizeLimit']))
{
// Make sure the directory isn't full.
$dirSize = 0;
$dir = @opendir($modSettings['attachmentUploadDir']) or fatal_lang_error('smf115b');
while ($file = readdir($dir))
{
if (substr($file, 0, -1) == '.')
continue;

$dirSize += filesize($modSettings['attachmentUploadDir'] . '/' . $file);
}
closedir($dir);

// Too big!  Maybe you could zip it or something...
if ($_FILES['attachment']['size'][$n] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024)
fatal_lang_error('smf126');
}

// Find the filename, strip the dir.
$destName = basename($_FILES['attachment']['name'][$n]);

// Check if the file already exists.... (for those who do not encrypt their filenames...)
if (!$user_info['is_admin'] && !empty($modSettings['attachmentEncryptFilenames']))
{
Titel: Re: No attachment limit for admins
Beitrag von: reznorsoft in Oktober 21, 2005, 12:17:10 NACHMITTAGS
Zitat von: malinaobenny in August 27, 2005, 08:23:55 VORMITTAG


i thought that if we should edit it, it should not just be for the over-all attachment limit, but edit more of the code below that, to allow more permissions to the admin.

would this be alright?

// Is the file too big?
if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
fatal_lang_error('smf122', false, array($modSettings['attachmentSizeLimit']));

// Have we reached the maximum number of files we are allowed?
$quantity++;
if (!$user_info['is_admin'] && !empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'])
fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));

// Check the total upload size for this post...
$total_size += $_FILES['attachment']['size'][$n];
if (!$user_info['is_admin'] && !empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
fatal_lang_error('smf122', false, array($modSettings['attachmentPostLimit']));

if (!$user_info['is_admin'] && !empty($modSettings['attachmentCheckExtensions']))
{
if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions']))))
fatal_error($_FILES['attachment']['name'][$n] . '.<br />' . $txt['smf123'] . ' ' . $modSettings['attachmentExtensions'] . '.', false);
}

if (!$user_info['is_admin'] && !empty($modSettings['attachmentDirSizeLimit']))
{
// Make sure the directory isn't full.
$dirSize = 0;
$dir = @opendir($modSettings['attachmentUploadDir']) or fatal_lang_error('smf115b');
while ($file = readdir($dir))
{
if (substr($file, 0, -1) == '.')
continue;

$dirSize += filesize($modSettings['attachmentUploadDir'] . '/' . $file);
}
closedir($dir);

// Too big!  Maybe you could zip it or something...
if ($_FILES['attachment']['size'][$n] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024)
fatal_lang_error('smf126');
}

// Find the filename, strip the dir.
$destName = basename($_FILES['attachment']['name'][$n]);

// Check if the file already exists.... (for those who do not encrypt their filenames...)
if (!$user_info['is_admin'] && !empty($modSettings['attachmentEncryptFilenames']))
{

I was thinking of doing the exact same thing .. I don't see why it wouldn't work .. guess I'm about to find out  ;)

though it seems you didn't add the string !$user_info['is_admin'] && to the first part of the code // Is the file too big?
if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
fatal_lang_error('smf122', false, array($modSettings['attachmentSizeLimit']));
Titel: Re: No attachment limit for admins
Beitrag von: Peter Duggan in Februar 17, 2007, 04:59:54 VORMITTAG
Zitat von: [Unknown] in September 26, 2004, 10:58:13 NACHMITTAGS
Post.php, find:
if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)

Replace:
if (!$user_info['is_admin'] && !empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)

So what's changed here over the past 2+ years that might stop this working?

NB I'm aware of the following:

Zitat von: [Unknown] in Oktober 17, 2004, 04:02:35 NACHMITTAGS
Maybe it's your per-post limit?

But still can't attach a 600K image with per post limit of 2000K and max attachment size of 200K 'disabled' as suggested above for admins (so that line at least remains unchanged since 2004!) and suspect there may now be some additional limiting factor?
Titel: Re: No attachment limit for admins
Beitrag von: bodyboard_jerez in Mai 28, 2007, 11:04:29 VORMITTAG
Hi, I have the 1.1.2 version and this Tips and Tricks doesn't runs for me...

Please, could you help me? Thanks a lot "!"
Titel: Re: No attachment limit for admins
Beitrag von: bodyboard_jerez in Juni 08, 2007, 08:09:59 VORMITTAG
Zitat von: bodyboard_jerez in Mai 28, 2007, 11:04:29 VORMITTAG
Hi, I have the 1.1.2 version and this Tips and Tricks doesn't runs for me...

Please, could you help me? Thanks a lot "!"

Somebody does this trick runs on 1.1.2 version? How please?
Titel: Re: No attachment limit for admins
Beitrag von: Kolya in Januar 21, 2012, 10:44:37 VORMITTAG
For SMF 2.02 to exempt the admin from upload size limits and file extension checks: Basically just add !$user_info['is_admin'] && to all these checks...

In Sources/Post.php:
FIND:
if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));

$quantity++;
if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'])
fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));

$total_size += $_FILES['attachment']['size'][$n];
if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));

if (!empty($modSettings['attachmentCheckExtensions']))
{
if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions']))))
fatal_error($_FILES['attachment']['name'][$n] . '.<br />' . $txt['cant_upload_type'] . ' ' . $modSettings['attachmentExtensions'] . '.', false);
}



REPLACE with:
if (!$user_info['is_admin'] && !empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024)
fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));

$quantity++;
if (!$user_info['is_admin'] && !empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'])
fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));

$total_size += $_FILES['attachment']['size'][$n];
if (!$user_info['is_admin'] && !empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));

if (!$user_info['is_admin'] && !empty($modSettings['attachmentCheckExtensions']))
{
if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions']))))
fatal_error($_FILES['attachment']['name'][$n] . '.<br />' . $txt['cant_upload_type'] . ' ' . $modSettings['attachmentExtensions'] . '.', false);
}


FIND:
// Check the total upload size for this post...
$total_size += $_FILES['attachment']['size'][$n];
if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
{
checkSubmitOnce('free');
fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
}


REPLACE with:
// Check the total upload size for this post...
$total_size += $_FILES['attachment']['size'][$n];
if (!$user_info['is_admin'] && !empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
{
checkSubmitOnce('free');
fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
}
Titel: Re: No attachment limit for admins
Beitrag von: michaeloeser in März 02, 2012, 04:19:05 VORMITTAG
Doesn´t seem to work for me. I´m the main and only administrator of my forum and although I made the changes to Post.php I´m not able to upload more and bigger files as defined in the attachment settings. Using SMF 2.0.2.

Any ideas?
Titel: Re: No attachment limit for admins
Beitrag von: Chalky in März 17, 2012, 10:48:23 VORMITTAG
Zitat von: michaeloeser in März 02, 2012, 04:19:05 VORMITTAG
Doesn´t seem to work for me. I´m the main and only administrator of my forum and although I made the changes to Post.php I´m not able to upload more and bigger files as defined in the attachment settings. Using SMF 2.0.2.

Any ideas?

For me neither.  I'm using 2.0.2, just made exactly the edits shown above, but nothing happened...
Titel: Re: No attachment limit for admins
Beitrag von: searchgr in Mai 09, 2012, 11:36:39 VORMITTAG
Any update here?
Titel: Re: No attachment limit for admins
Beitrag von: mybiafraland in Juni 20, 2012, 08:49:42 VORMITTAG
waiting for update as well
Titel: Re: No attachment limit for admins
Beitrag von: Kays in Juni 20, 2012, 10:36:40 VORMITTAG
Hi, look in Subs-Post.php for the same set of checks and make the recommended change to those also.
Except, instead of !$user_info['is_admin'] use !$context['user']['is_admin']
Titel: Re: No attachment limit for admins
Beitrag von: Elmacik in Juni 21, 2012, 04:50:59 VORMITTAG
A smoother way I told here:
http://www.simplemachines.org/community/index.php?topic=479722.0
Titel: Re: No attachment limit for admins
Beitrag von: dougiefresh in Dezember 06, 2014, 12:06:02 NACHMITTAGS
Zitat von: Chalky in März 17, 2012, 10:48:23 VORMITTAG
Zitat von: michaeloeser in März 02, 2012, 04:19:05 VORMITTAG
Doesn´t seem to work for me. I´m the main and only administrator of my forum and although I made the changes to Post.php I´m not able to upload more and bigger files as defined in the attachment settings. Using SMF 2.0.2.

Any ideas?

For me neither.  I'm using 2.0.2, just made exactly the edits shown above, but nothing happened...
The reason it doesn't work is it's incomplete.  Modifications must be made to the Themes/default/Post.template.php as well.... 



In Sources/Post.php, find and replace:
Code (find) Auswählen
$context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit'])
Code (Replace) Auswählen
$context['num_allowed_attachments'] = ($user_info['is_admin'] || empty($modSettings['attachmentNumPerPostLimit']))

In Sources/Subs-Post.php, find and replace:
Code (Find) Auswählen
function createAttachment(&$attachmentOptions)
{
global

Code (Replace) Auswählen
function createAttachment(&$attachmentOptions)
{
global $user_info,


Code (Find) Auswählen
if (!empty($modSettings['attachmentSizeLimit']) && $attachmentOptions['size'] > $modSettings['attachmentSizeLimit'] * 1024)
Code (Replace) Auswählen
if (!$user_info['is_admin'] && !empty($modSettings['attachmentSizeLimit']) && $attachmentOptions['size'] > $modSettings['attachmentSizeLimit'] * 1024)

In Themes/default/Post.template.php, find and replace these:
Code (Find) Auswählen
function template_main()
{
global

Code (Replace) Auswählen
function template_main()
{
global $user_info,


Code (Find) Auswählen
if ($context['num_allowed_attachments'] > 1)]]></search>
Code (Replace) Auswählen
if ($user_info['is_admin'] || $context['num_allowed_attachments'] > 1)

Code (Find) Auswählen
var allowed_attachments = ', $context['num_allowed_attachments'], ';
Code (Replace) Auswählen
var allowed_attachments = ', (empty($user_info['is_admin']) ? $context['num_allowed_attachments'] : 100), ';

Code (Find) Auswählen
if (!empty($modSettings['attachmentCheckExtensions']))
Code (Replace) Auswählen
if (!$user_info['is_admin'] && !empty($modSettings['attachmentCheckExtensions']))

Code (Find) Auswählen
if (!empty($context['attachment_restrictions']))
Code (Replace) Auswählen
if (!$user_info['is_admin'] && !empty($context['attachment_restrictions']))




I've posted up a mod based on this thread with all my modifications (9 operations total) here: No Attachment Limit for Admins (http://custom.simplemachines.org/mods/index.php?mod=3997).  It hasn't been approved yet....
Titel: Re: No attachment limit for admins
Beitrag von: dougiefresh in Dezember 11, 2014, 07:55:54 NACHMITTAGS
It occurs to me that the admin check could be converted into a permission-based group thingy.....
Titel: Re: No attachment limit for admins
Beitrag von: dougiefresh in Dezember 21, 2014, 07:39:34 VORMITTAG
No attachment limits for membergroups (http://custom.simplemachines.org/mods/index.php?mod=3997) mod has been released, if anyone is interested......
Titel: Re: No attachment limit for admins
Beitrag von: alastairbrian in März 19, 2015, 01:58:29 VORMITTAG
Zitat von: bodyboard_jerez in Mai 28, 2007, 11:04:29 VORMITTAG
Hi, I have the 1.1.2 version and this Tips and Tricks doesn't runs for me...

Please, could you help me? Thanks a lot "!"

It also not working for my version 1.1.2
Titel: Re: No attachment limit for admins
Beitrag von: Kindred in März 19, 2015, 07:28:27 VORMITTAG
if you are running 1.1.2, you are 18 revisions behind and need to upgrade ASAP.