Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-17758

Attaching too many files -> error message does not appear

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 3.3.19
    • Attachments
    • PHP version: 8.3.6
      OS: Ubuntu Linux 24.04
      Database server: MySQL(i) 10.11.14-MariaDB-0ubuntu0.24.04.1
      Browser: LibreWolf 158.0.1-2

      Using phpBB 3.3.19, I'm getting this issue consistently, even with extensions disabled.

      To reproduce:

      1. Set max attachments per post to, let's say, 3.
      2. Log in as regular user.
      3. Create a new topic with summary like: Attachment test (or edit an already existing topic with not more than 3 attachments).
      4. In the Attachment tab, upload more than 3 files (or more than what you are still allowed to upload).

      Result:

      • What is OK: In the status column, you'll see a warning icon. If you click on it, you'll see "Error: Cannot add another attachment, 3 is the maximum."
      • What is NOT OK: In the console I can see Uncaught TypeError: can't access property "name", error.file is undefined. After removing attachments and adding them again, the upload never starts, you have to reload the page to start uploading again.

      Stack trace:

      Uncaught TypeError: can't access property "name", error.file is undefined
          <anonymous> https://my.site.com/phpbb/assets/javascript/plupload.js?assets_version=11:540
          dispatchEvent https://my.site.com/phpbb/assets/plupload/plupload.full.min.js?assets_version=11:29
          trigger https://my.site.com/phpbb/assets/plupload/plupload.full.min.js?assets_version=11:13
          handleMaxFilesReached https://my.site.com/phpbb/assets/javascript/plupload.js?assets_version=11:402
          <anonymous> https://my.site.com/phpbb/assets/javascript/plupload.js?assets_version=11:560
          dispatchEvent https://my.site.com/phpbb/assets/plupload/plupload.full.min.js?assets_version=11:29
          trigger https://my.site.com/phpbb/assets/plupload/plupload.full.min.js?assets_version=11:13
      (...)
      

      Analysis of the problem:

      Function phpbb.plupload.handleMaxFilesReached calls: phpbb.plupload.uploader.trigger('Error', { message: phpbb.plupload.lang.TOO_MANY_ATTACHMENTS });, but this error object has no file field, just the message, therefore fails to access it at line error.file.name = plupload.xmlEncode(error.file.name);.

      Workaround I tried:

      After adding this hacky line to the JavaScript code just before error.file.name is accessed:

      error.file = {name: arguments[0].files[0].name}
      

      The error message pops up without having to click on the first warning icon. => It is immediately clear what is going on. Which seems to indicate that the proper behavior should be something like this. Hence the title of this topic.

      This workaround also seems to fix the problem that uploads are now broken until page reload. I tested it by editing assets/javascript/plupload.js as mentioned:

      /**
       * Fires when an error occurs.
       */
      phpbb.plupload.uploader.bind('Error', function(up, error) {
              if (!error.file) error.file = {name: arguments[0].files[0].name};   // <-- Hacky line added.
              error.file.name = plupload.xmlEncode(error.file.name);
      (...)
      

            Unassigned Unassigned
            SirWolf SirWolf
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: