views:

92

answers:

1

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.

+2  A: 
$new_filename = $primary_key . '.' . pathinfo($orig_filename, PATHINFO_EXTENSION);
Scott Evernden
thanks man.Thanks a lot
Scott Evernden
thans again man:please have a look at my other quetion http://stackoverflow.com/questions/1482897/geting-a-list-of-all-files-in-a-directory