diff --git a/include/class.forms.php b/include/class.forms.php
index 7d7c585e9e8629ab2d09f74c0f50158dbbab0006..9c5bafebd3c94aa616ce8c3597d5e60ca6fb9f09 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -4401,12 +4401,12 @@ class FileUploadWidget extends Widget {
         );
         $maxfilesize = ($config['size'] ?: 1048576) / 1048576;
         $files = array();
-        $new = array_fill_keys($this->field->getClean(), 1);
+        $new = array_flip($this->field->getClean());
 
         //get file ids stored in session when creating tickets/tasks from thread
         if (!$new && is_array($_SESSION[':form-data'])
                   && array_key_exists($this->field->get('name'), $_SESSION[':form-data']))
-          $new = array_fill_keys($_SESSION[':form-data'][$this->field->get('name')], 1);
+          $new = $_SESSION[':form-data'][$this->field->get('name')];
 
         foreach ($attachments as $a) {
             unset($new[$a->file_id]);
@@ -4493,7 +4493,7 @@ class FileUploadWidget extends Widget {
         // Files attached to threads where we are creating tasks/tickets are allowed
         if (isset($_SESSION[':form-data'][$this->field->get('name')])) {
           foreach ($_SESSION[':form-data'][$this->field->get('name')] as $key => $value)
-            $allowed[$value] = 1;
+            $allowed[$key] = $value;
         }
 
         // Canned attachments initiated by this session
diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php
index 351f66370fa9fd09090f4f5bf12934cbeb961a9c..2bccfd311586643492e48b0b987f6d33c0a95d2d 100644
--- a/include/class.thread_actions.php
+++ b/include/class.thread_actions.php
@@ -524,7 +524,7 @@ JS
               unset($_SESSION[':form-data'][$k]);
               foreach ($this->entry->getAttachments() as $a)
                   if (!$a->inline && $a->file) {
-                    $_SESSION[':form-data'][$k][] = $a->file->getId();
+                    $_SESSION[':form-data'][$k][$a->file->getId()] = $a->getFilename();
                   }
         }
 
diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php
index 96ee98bbdeac440975ad94301eae6b2959c16569..62a0c60fc0f0c30833e05b6f5619ac3d2717245f 100644
--- a/include/staff/ticket-open.inc.php
+++ b/include/staff/ticket-open.inc.php
@@ -30,7 +30,7 @@ if (!$user && $_GET['tid'] && ($entry = ThreadEntry::lookup($_GET['tid']))) {
          unset($_SESSION[':form-data'][$k]);
         foreach ($entry->getAttachments() as $a) {
           if (!$a->inline && $a->file) {
-            $_SESSION[':form-data'][$k][] = $a->file->getId();
+            $_SESSION[':form-data'][$k][$a->file->getId()] = $a->getFilename();
           }
         }
      }