diff --git a/include/class.file.php b/include/class.file.php
index cc90630666e59c831f144bb5743ed5f41611e74a..98b66e46b74d25336a2936b2d41ca531e5e0da44 100644
--- a/include/class.file.php
+++ b/include/class.file.php
@@ -322,14 +322,16 @@ class AttachmentFile {
         }
 
         // Check and see if the file is already on record
-        $sql = 'SELECT id FROM '.FILE_TABLE
+        $sql = 'SELECT id, key FROM '.FILE_TABLE
             .' WHERE signature='.db_input($file['signature'])
             .' AND size='.db_input($file['size']);
 
         // If the record exists in the database already, a file with the
         // same hash and size is already on file -- just return its ID
-        if ($id = db_result(db_query($sql)))
+        if (list($id, $key) = db_fetch_row(db_query($sql))) {
+            $file['key'] = $key;
             return $id;
+        }
 
         $sql='INSERT INTO '.FILE_TABLE.' SET created=NOW() '
             .',type='.db_input(strtolower($file['type']))