I am making File Uploader and uploaded same file twice it replaced original. how to avoid this?? how to prevent Duplicate File conflict in PHP? How will you manage files with same name , if you have FILE UPLOAD system on your server?? how to handle Duplicate file upload??
How can one avoid duplicate naming issues? How to overcome problem of File with Same name Already exists on server? How can you Rename Uploaded files to prevent Duplicate names?
Here are few ways to do so.
- Attach (1),(2) etc. in front of uploaded file.
This can be one of the solutions.. But if your server has 100′s of files with same name?? (1)(2)..(100) and original one , then how to do this?? This will cause to run a big loop for you.
Example:
You are uploading a file say 1.jpg on your server. There is a file with name 1.jpg on your server already.. then in your upload Script in PHP what you will do? You will check if file with current name exists on server.. If so then you will attach 1(1).jpg.
But what if you have 1.jpg,1(1).jpg, …. ,1(100).jpg present on server? Is this feasible to run a big loop???? No!! So what to do?? There is a next way for you!
- Attach Time Stamp in front of Uploaded file name!
Oh!! What does that mean?? It’s simple .. You will check if “1.jpg” is already there on server or not. If it’s there then Simply Generate a Time Stamp, i.e. Get current Time as , YYYY-MM-DD-HH-MM-SS .(without – or with – as your wish) And then Just attach it against file name i.e. 1(Timestamp).jpg
So it simply means .. You won’t be ever having naming conflicts in life :P
You can apply this Technique in all type of Server side scripting i.e. PHP , JAVA , ASP , ASP.NET and so on.
Search Terms
- File Upload with same name on server
- File upload name conflict
- Uploading file with same name on server
- how to upload file with same name on server php
- File upload issues
- Change Upload file Name
- Rename Uploaded files
- Rename uploaded file without conflict
- Upload file With Same Name
- how to upload file with same name on server JSP
- how to upload file with same name on server ASP
- how to upload file with same name on server Servlet
- how to rename Upload File
- handle duplicate files upload
- how to handle duplicate files upload




