- // Erase any lingering attachments
- foreach ($attachments as $info)
- {
- if (file_exists($attachment_dir . $info['localfilename']))
- {
- unlink($attachment_dir . $info['localfilename']);
- }
- }
+/* Erase any lingering attachments */
+if (! isset($attachments)) {
+ $attachments = array();
+}
+$hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+foreach ($attachments as $info) {
+ $attached_file = "$hashed_attachment_dir/$info[localfilename]";
+ if (file_exists($attached_file)) {
+ unlink($attached_file);
+ }
+}