Overwrite save attachments files when duplicate

Hi i have a function that downloads 5-10 images from a site and sends it to my mail, i have another function that saves all this images in a folder using save attachment. I am getting a error because sometimes the images have the same name. I want to simply overwrite the image if it has duplicate names upon save attachments. any ideas ?