On Monday, I upload dogs.png as my profile picture on my Drupal site.

On Tuesday, I change the image to something else (but keep the name "dogs.png") and upload it as my associate's profile picture.

What will Drupal do to resolve this conflict?

1 Answer 1


It will rename the second file for you. If dogs.png exists, Drupal will try dogs_0.png, dogs_1.png and so on, until it finds an unused filename.

The behaviour comes from the $replace parameter to file_save_data(), which can be one of the following:

  • FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with the destination name exists then its database entry will be updated. If no database entry is found then a new one will be created.
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.

The default is FILE_EXISTS_RENAME, which is used for managed file form elements like the user profile picture, and file field widgets too.

  • 1
    This is super enforced in D8 too (FILE_EXISTS_RENAME) for core file upload field.
    – Kevin
    Commented Apr 11, 2017 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.