There is an unconsistency within file.inc that affects the file replacement functionality when uploading a file and that prevent to use it as it's expected.
file_save_upload has a $replace parametre which is treated as a boolean. However, file_move (first) and file_copy (later) are expecting strings ('FILE_EXISTS_RENAME', 'FILE_EXISTS_REPLACE' or 'FILE_EXISTS_ERROR'). None of these two other functions treate a TRUE value as a 'FILE_EXISTS_REPLACE'.
Using, then, file_save_upload with a $replace param as TRUE doesn't replace the uploaded file.
I patched file_save_upload to work as expected but maybe somone could find a smarter way of fixing this.
Also, previous versions of drupal have the same problem. If this patch is finally commited to core please consider to commit it to 4.6.5.
Comment | File | Size | Author |
---|---|---|---|
#1 | file_inc_0.patch | 588 bytes | killes@www.drop.org |
file.inc_2.patch | 822 bytes | robertgarrigos | |
Comments
Comment #1
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedFILE_EXISTS_REPLACE etc are numerical constants. FILE_EXISTS_REPLACE has the value 1.
I cannot see how this is critical. I have re-rolled the patch, it is just a code cleanup.
Comment #2
Dries CreditAttribution: Dries commentedCommitted. Thanks.
Comment #3
(not verified) CreditAttribution: commented