MyBB Community Forums

Full Version: Uploading attachment disappears when trying to attach to forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Recently upgraded to myBB version 1.8.X below are the details. When trying to attach a document to the thread and click on "add attachment" the document disappears, it does not give an error.

Below is the code for "post_attachments_new" template

<tr>
<td class="trow1" width="1"><img src="{$theme['imgdir']}/paperclip.png" alt="" /></td>
<td class="trow1" style="white-space: nowrap"><strong>{$lang->new_attachment}</strong> <input type="file" name="attachment" size="30" class="fileupload"/></td>
<td class="trow1" style="white-space: nowrap" align="center">{$attach_update_options} {$attach_add_options}</td>
</tr>



MyBB Version 1.8.24
PHP Version 5.4.16

SQL Engine MySQLi 10.5.11

Any help will be highly appreciated.

[size=1]M[/size]
When the add attachment is clicked on new reply, a javascript error flashes for few seconds, the error says php_max_file_uploads is not defined checkAttachments (post.js?ver=1808)

This version of myBB is using php_max_file_uploads in the post.js file
Below is the function from post.js
checkAttachments: function()
        {
                var files = $("input[type='file']");
                var file = files.get(0);
                if (!file)
                {
                        return true;
                }

                if (file.files.length > php_max_file_uploads && php_max_file_uploads != 0)
                {
                        alert(lang.attachment_too_many_files.replace('{1}', php_max_file_uploads));
                        file.value="";
                        return false;
                }

                var totalSize = 0;
                files.each(function()
                {
                        for (var i = 0; i < this.files.length; i++)
                        {
                                totalSize += this.files[i].size;
                        }
                });

                if (totalSize > php_max_upload_size && php_max_upload_size > 0)
                {
                        var php_max_upload_size_pretty = Math.round(php_max_upload_size / 1e4) / 1e2;
                        alert(lang.attachment_too_big_upload.replace('{1}', php_max_upload_size_pretty));
                        file.value="";
                        return false;
                }

                return true;
        }

Can anyone please help how and where this variable is configured?

I checked php.ini file and it contain a variable

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

Does myBB require another variable php_max_file_uploads set? Is there anything that we are missing? Any help will be greatly appreciated.
The php_max_file_uploads variable is defined in the post_javascript template, read the following page:
https://docs.mybb.com/1.8/install/upgrade/#themes
(2021-08-11, 09:26 PM)Omar G. Wrote: [ -> ]The php_max_file_uploads variable is defined in the post_javascript template, read the following page:
https://docs.mybb.com/1.8/install/upgrade/#themes

Omar,

For some reason when I try searching the template you shared, it cannot be find

"No templates were found with the title 'post_javascript'"

Does this need to be downloaded or imported?
Look in your theme post templates.
(2021-08-16, 05:21 PM)nixer55 Wrote: [ -> ]Look in your theme post templates.

Thanks for your response but post_javascript is missing under post templates (screen snippet below)

[attachment=44290]
The post_javascript template was added in 1.8.18 :
https://github.com/mybb/mybb/blob/420b31....xml#L9518

You said you did upgrade, from which version did you upgrade ? Did you run the upgrade script ? Were there any issues while upgrading ?
Please refer to the following if you did not run the upgrade script :
https://docs.mybb.com/1.8/install/upgrade/
(2021-08-16, 08:33 PM)Omar G. Wrote: [ -> ]The post_javascript template was added in 1.8.18 :
https://github.com/mybb/mybb/blob/420b31....xml#L9518

You said you did upgrade, from which version did you upgrade ? Did you run the upgrade script ? Were there any issues while upgrading ?

Omar,

I did ran the upgrade not sure why this template did not get updated. Anyhow, I tried creating a new template "post_javascript" as following (got this from myBB_theme.xml):

<script type="text/javascript">
lang.attachment_too_many_files = "{$lang->attachment_too_many_files}";
lang.attachment_too_big_upload = "{$lang->attachment_too_big_upload}";
php_max_upload_size = {$php_max_upload_size};
php_max_file_uploads = {$php_max_file_uploads}";
</script>
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/post.js?ver=1823"></script>

After which it still was erroring out same, so I hardcoded the value:

<script type="text/javascript">
lang.attachment_too_many_files = "{$lang->attachment_too_many_files}";
lang.attachment_too_big_upload = "{$lang->attachment_too_big_upload}";
php_max_upload_size = {$php_max_upload_size};
php_max_file_uploads = "20";
</script>
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/post.js?ver=1823"></script>

Still no luck. I apologize for reaching out again and again but I really would like to resolve this issue.

Thanks.
Upload all fresh MyBB files matching your installed version, or even better, perhaps upgrade to the latest.

Then run the upgrade script once again. I'm guessing either your files or DB is outdated or simply doesn't match each other or the version you are supposed to be in.

This template should be listed as a core template, lets you fix that first.
Pages: 1 2