Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment: a bug and a mod to allow multi-attachment selection #3139

Closed
Sama34 opened this issue Apr 19, 2018 · 0 comments
Closed

Attachment: a bug and a mod to allow multi-attachment selection #3139

Sama34 opened this issue Apr 19, 2018 · 0 comments
Assignees
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:bug Type: Bug. An issue causing error / flaw / malfunction
Milestone

Comments

@Sama34
Copy link
Contributor

Sama34 commented Apr 19, 2018

First, the bug (1.8.14).  The situation: one has uploaded an attachment for a new/edit post and one has selected another file to be uploaded but "Add Attachment to upload the second attachment has not been clicked yet.  If at that point, one clicks on "Remove Attachment", the selected attachment will be uploaded.

Now an improvement.  I was interested in allowing multi-attachments adds.  I found a plugin that added that capability, but it also added a number of other features.  I found the plugin unusable because of various bugs, many of which were related to features other than supporting multifile upload.  I implemented the following fairly straight-forward changes to allow the multi-file uploads.  If anyone wants to try it, and provide feedback, at some point I may turn it into a plugin.

Uploaded files come into the *.php code via the variables "$_FILES['attachment'][$field]", where $field has various values like 'name' and 'size' for various aspects of the uploaded file. For multi-file uploads, those variables become arrays instead of singular values.  Where those variables are used, the following code segment must be inserted.

Code:        $fields = array ('name', 'type', 'tmp_name', 'error', 'size');
        if (is_array($_FILES['attachment']['name']))
        {
            // Already in multi-attachment array format
            $attachments = $_FILES;
        }
        else
        {
            // Convert original-style non-array $_FILES['attachment'][$field] to array format in $attachments
            $attachments = array('attachment' => array());
            foreach ($fields as $field)
                $attachments['attachment'][$field] = array($_FILES['attachment'][$field]);
        }
        foreach ($attachments['attachment']['name'] as $key => $name)
        {
            // Convert array $attachments['attachment'][$field][$key] to non-array format in $FILE
            $FILE = array('attachment' => array());                
            foreach ($fields as $field)
                $FILE['attachment'][$field] = $attachments['attachment'][$field][$key];
Step 1: The affected files are newthread.php, editpost.php and newreply.php, around line 225, give or take, in each.  In each file, insert the code before the first "if" statements that process the attachment (and add another closing curly brace for the added "foreach" statement).

Step 2: In that "if" staement, chnage all references to "$_FILES" to "$FILE".

Example: in newthread.php, the new code segment would look like this:
[attachment=40094]

Step 4: Change the "input" tag in template "post_attachments_new" to have name "attachment[]" (braces added) and the keyword "multiple".
Code:<input type="file" name="attachment[]" size="30" class="fileupload" multiple/>
Older browsers may still be limited to single attachment uploads but it still should work for that.

Original thread: Attachment: a bug and a mod to allow multi-attachment selection

@Sama34 Sama34 added b:1.8 Branch: 1.8.x t:bug Type: Bug. An issue causing error / flaw / malfunction s:confirmed Status: Confirmed. Retested and found the issue exists labels Apr 19, 2018
@Sama34 Sama34 self-assigned this Apr 19, 2018
@Sama34 Sama34 added this to the 1.8.16 milestone Apr 19, 2018
@effone effone added s:resolved Status: Resolved. Solution implemented or scheduled and removed s:confirmed Status: Confirmed. Retested and found the issue exists labels Apr 30, 2018
@effone effone removed this from the 1.8.16 milestone Jun 12, 2018
@effone effone added s:confirmed Status: Confirmed. Retested and found the issue exists and removed s:resolved Status: Resolved. Solution implemented or scheduled labels Jul 15, 2018
@effone effone added this to the 1.8.18 milestone Jul 15, 2018
@effone effone removed this from the 1.8.18 milestone Jul 23, 2018
@effone effone added s:resolved Status: Resolved. Solution implemented or scheduled and removed s:confirmed Status: Confirmed. Retested and found the issue exists labels Aug 1, 2018
@effone effone added this to the 1.8.18 milestone Aug 1, 2018
euantorano pushed a commit that referenced this issue Aug 11, 2018
…ection (#3373)

* Fixes #3139 Attachment: a bug and a mod to allow multi-attachment selection

* Wasnt working

* Added javascript to post.js, considering php limits and appropriate translations to lang

* Fixed editpost attachments, coding style and bumped up template versions

* Fixed braces and no-script behaviour of multiple attachments, edited functions_upload to do fewer queries

* Remove backticks that break Postgres
euantorano pushed a commit that referenced this issue Aug 13, 2018
…ection (#3390)

* Fixes #3139 Attachment: a bug and a mod to allow multi-attachment selection

* Wasnt working

* Added javascript to post.js, considering php limits and appropriate translations to lang

* Fixed editpost attachments, coding style and bumped up template versions

* Fixed braces and no-script behaviour of multiple attachments, edited functions_upload to do fewer queries

* Remove backticks that break Postgres

* Fixed bug with empty $filenames in attachments and removed unnecessary variable from query
lairdshaw pushed a commit to lairdshaw/mybb that referenced this issue Oct 11, 2021
… selection (mybb#3373)

[Rebased for 1.9 by Laird]

* Fixes mybb#3139 Attachment: a bug and a mod to allow multi-attachment selection

* Wasnt working

* Added javascript to post.js, considering php limits and appropriate translations to lang

* Fixed editpost attachments, coding style and bumped up template versions

* Fixed braces and no-script behaviour of multiple attachments, edited functions_upload to do fewer queries

* Remove backticks that break Postgres
lairdshaw pushed a commit to lairdshaw/mybb that referenced this issue Oct 11, 2021
… selection (mybb#3390)

* Fixes mybb#3139 Attachment: a bug and a mod to allow multi-attachment selection

* Wasnt working

* Added javascript to post.js, considering php limits and appropriate translations to lang

* Fixed editpost attachments, coding style and bumped up template versions

* Fixed braces and no-script behaviour of multiple attachments, edited functions_upload to do fewer queries

* Remove backticks that break Postgres

* Fixed bug with empty $filenames in attachments and removed unnecessary variable from query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:bug Type: Bug. An issue causing error / flaw / malfunction
Projects
None yet
Development

No branches or pull requests

2 participants