Replacing substring in a string
- by user177785
I am uploading a image file to the server.
Now after uploading the file to the server I need to rename the file with an id, but the extension of the file should be retained.
Eg: if I upload the file image1.png then my server script should retain the extension .png. But I need to change the substring to some other substring (primary key of db).
image1.png should be renamed to 123.png
image2.jpg should be renamed to somevalue.jpg
The image can be of any extension like .png, .jpg, .jpeg etc.
I want to rename then in such a way that the image/file extension should be retained.