diff --git a/include/class.canned.php b/include/class.canned.php
index 4ef801205dc1c9b8d3b5875e0045d1326e523ea9..6bd2e99d0840490d462ca5c72641e19f3f7517b7 100644
--- a/include/class.canned.php
+++ b/include/class.canned.php
@@ -134,6 +134,7 @@ extends VerySimpleModel {
 
                 $resp['files'] = array();
                 foreach ($this->getAttachedFiles(!$html) as $file) {
+                    $_SESSION[':cannedFiles'][$file->id] = 1;
                     $resp['files'][] = array(
                         'id' => $file->id,
                         'name' => $file->name,
@@ -146,9 +147,6 @@ extends VerySimpleModel {
                     $resp['response'] = Format::html2text($resp['response'], 90);
                 }
 
-                foreach ($resp['files'] as $f)
-                    $_SESSION[':cannedFiles'][$f['file_id']] = 1;
-
                 return Format::json_encode($resp);
                 break;
             case 'html':