Renaming uploaded files with extension.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DevilDust
Forum Newbie
Posts: 7
Joined: Tue Nov 19, 2002 11:22 pm
Location: USA

Renaming uploaded files with extension.

Post by DevilDust »

Here's what I'm trying to do. I've got a form which has a field to upload an image. (input type="file" name="file") Anyway, what I'm trying to do... since I'm going to be putting these images into a database, is rename the image to a random image name.. I've gotten to the point where it would upload the image with a random number... but no extension....

function gfe($filename) //function to get image's extension
{
$pathinfo = pathinfo($filename);
return $pathinfo['extension'];
}

$extension = gfe($file); //calls function and puts the extension into a var

//this might be where I'm screwing up... I'm trying to generate a random number and then add the extension to it
$imgname = time() . $REMOTE_HOST . $extension;

//Then I have the copy function
copy($file, "/path/to/images/$imgname");

Any ideas where I went wrong, or an easier way to do this?
Post Reply