If you don't mark a file field as "Multiple values" it becomes a single value field: There is only one file allowed to be uploaded. To make a file field delete its former file once a new one is uploaded the former one has to be marked as "Delete". Unfortunately the file field is always marked as to be deleted even if there is no new file uploaded. The mark will be set internal ($form[$fieldname][$delta]['remove']['#value'] = 1) after submitting the HTML form so there is no way to unmark it from the formular the file field belongs to. This makes the file field to delete its content every time you submit the form. The attached patch will fix this by marking it only if there is a new file uploaded.

CommentFileSizeAuthor
filefield_delete_original_item.patch733 bytesfuerst

Comments

kevinwalsh’s picture

Thanks Fuerst, this is helpful!

dopry’s picture

Status: Active » Closed (duplicate)

This should be fixed in HEAD for Drupal 5. I'll work on a backport to 4.7 tomorrow.

http://drupal.org/node/107240