How to upload an image file without overwriting the existing one

Normally, when you upload a file or image, it overwrites the file if the same file name already exists. In this post , we will learn how to solve this issue by using a small trick and the trick is using random number within file name part.

I would recommend you read my one of the previous post how to upload an image to have some basic knowledge about uploading an image file.

Here are few steps to upload an image using PHP language

step 1: make an input of file type and add a submit button within form body

Note: make sure that encryption type enctype=”multipart/form-data” should be the part of form definition.

step 2: now you have to handle POSt variables received when user will press submit
you will see that the name part of the file is separated and a random number is added at the end of file name part.

Download the source code for upload an image without overwriting the existing one

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.