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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

killes@www.drop.org’s picture

Version: 4.7.0-beta4 » x.y.z
Priority: Critical » Minor
FileSize
588 bytes

FILE_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.

Dries’s picture

Status: Needs review » Fixed

Committed. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)