I want my site to host some images. The user is able to upload images as a content type.

If two users create content and upload images with the exact same name (myImage.png), will the older image file be overwritten in the server (and therefore both content entries would end up with the same image file)?

If yes, it is rather troubling. So now I wonder: is there a module that renames the uploaded file so it will not collide with other uploaded files?

I have searched for a couple ones, not exactly tested them since they seem to add too much extra functionality I just don't need: I like the default file uploading system that comes with Drupal 7. I just want it to avoid name collisions (if it happens).

3 Answers 3


You don't need to worry about the renaming of the images; Drupal does that for you by default :)
Lets say if you upload image1.jpg, and again someone else does the same the second file will be renamed image1_0.jpg.


You might find some information about how to code changing file names in the File Path module.

File (Field) Paths allows you to automatically sort and rename your uploaded files using token based replacement patterns to maintain a nice clean filesystem.

  • Thanks, I will take a look. One little thing though, it says "[D6] Audio module." - I didn't mention it but it is possible I will want to also upload audio files. Since it says [D6] I am assuming it means it is not possible to use this for audio uploads then?
    – Saturn
    Commented Sep 19, 2012 at 5:05
  • I think audio module is only for Drupal 6. So you have to find another solution to manage Audio. Please check it might work for you.. Good luck :-) Commented Sep 19, 2012 at 5:08
  • Though Drupal will rename files automatically, but File Path Module will help you to manage files in proper folder structure. Commented Sep 19, 2012 at 5:10
  • Oh, you're right. Yeah, this module seems to be able to achieve this! Although managing files in proper folder structure is not a priority for me (not now at least)
    – Saturn
    Commented Sep 19, 2012 at 5:11

Also you can set a pattern for you files and with random or timestamp part it never duplicated

you can use hook_file_persave

function yourmodulename_file_presave($file) {
  $parts = pathinfo($file->filename);
  $file->filename = 'mystring_'.$file->uid .'_'. $file->timestamp . '.' . $parts['extension'];

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.