First, find the extension:
$pos = strrpos($filename, '.');
if($pos === false)
$ext = ""; // file has no extension; do something special?
$ext = substr($filename, $pos); // includes the period in the extension; do $pos + 1 if you don't want it
Then call your file anyhow you want, and append to the name the extension:
$newFilename = "foobar" . $ext;
move_uploaded_file($_FILES['picture']['tmp_name'], 'peopleimages/' . $newFilename);
EDIT Thinking of it, none of this is optimal. File extensions most often describe the file type, but this is not always the case. For instance, you could rename a .png file to a .jpg extension, and most applications would still detect it is as a png file. Other than that, certain OSes simply don't use file extensions to determine the type of a file.
With $_FILE
uploads, you are also given a type
element which represents the MIME type of the file you've received. If you can, I suggest you rely on it instead of on the given extension:
$imagetypes = array(
'image/png' => '.png',
'image/gif' => '.gif',
'image/jpeg' => '.jpg',
'image/bmp' => '.bmp');
$ext = $imagetypes[$_FILES['myfile']['type']];
You can have a more complete list of MIME types here.