Jump to content

Renaming an image in PHP


angelali

Recommended Posts

Hello, I made a site where to upload images. The images are saved to a directory (folder). After someoe uploads an image, he gets the link. For example, if someone has an image called "xxx.jpg", he gets the url like this: www.example.com/upload/xxx.jpg.

 

What I want is, when someone uploads an images, the name of the image change to random numbers. I know the PHP function rand() and rename () function, but the only problem is, it is renaming the file without considering the file extension.

 

Here is a sample of my codes:

 

$image = htmlentities($_FILES['file']['name']);
$number = rand(1,1000);
$newname = rename ($image, $number);
echo $newname

 

So, can someone tell me, how to rename images but taking into consideration of the file extension? If the image is xxx.jpg, I want it like 123.jpg not 123.

Link to comment
https://forums.phpfreaks.com/topic/258267-renaming-an-image-in-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.