diff --git a/include/class.forms.php b/include/class.forms.php
index c4d6ea44e58da9266fce504a21b0f08f319d3615..7e0b829199f65e40ce4b8ebb9ae53a50d1eafc3a 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -4366,6 +4366,12 @@ class FileUploadWidget extends Widget {
         $maxfilesize = ($config['size'] ?: 1048576) / 1048576;
         $files = $F = array();
         $new = array_fill_keys($this->field->getClean(), 1);
+
+        //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);
+
         foreach ($attachments as $a) {
             $F[] = $a->file;
             unset($new[$a->file_id]);
@@ -4449,6 +4455,12 @@ class FileUploadWidget extends Widget {
         if (isset($_SESSION[':uploadedFiles']))
             $allowed += $_SESSION[':uploadedFiles'];
 
+        // 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;
+        }
+
         // Canned attachments initiated by this session
         if (isset($_SESSION[':cannedFiles']))
            $allowed += $_SESSION[':cannedFiles'];
diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php
index ee0c8b16d9b98868144375ad96a78d60c89503f9..08e83dccef789b4cfc8aaf1f4ca3a8833b0f21a5 100644
--- a/include/class.thread_actions.php
+++ b/include/class.thread_actions.php
@@ -512,9 +512,11 @@ JS
                 'description' => Format::htmlchars($this->entry->getBody()));
         if (($f= TaskForm::getInstance()->getField('description'))) {
               $k = 'attach:'.$f->getId();
+              unset($_SESSION[':form-data'][$k]);
               foreach ($this->entry->getAttachments() as $a)
-                  if (!$a->inline && $a->file)
-                      $vars[$k][] = $a->file->getId();
+                  if (!$a->inline && $a->file) {
+                    $_SESSION[':form-data'][$k][] = $a->file->getId();
+                  }
         }
 
         return $this->getTicketsAPI()->addTask($this->getObjectId(), $vars);
diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php
index 2606bb736fb852d5b66329257ecf6b70231c36af..5185c11d7549f4f66e83be8456c42fb877dc22e1 100644
--- a/include/staff/ticket-open.inc.php
+++ b/include/staff/ticket-open.inc.php
@@ -15,9 +15,12 @@ if (!$user && $_GET['tid'] && ($entry = ThreadEntry::lookup($_GET['tid']))) {
 
      if (($m= TicketForm::getInstance()->getField('message'))) {
          $k = 'attach:'.$m->getId();
-        foreach ($entry->getAttachments() as $a)
-            if (!$a->inline && $a->file)
-                $_SESSION[':form-data'][$k][] = $a->file->getId();
+         unset($_SESSION[':form-data'][$k]);
+        foreach ($entry->getAttachments() as $a) {
+          if (!$a->inline && $a->file) {
+            $_SESSION[':form-data'][$k][] = $a->file->getId();
+          }
+        }
      }
 }