When you copy the file from the /tmp upload directory to where it will be residing, you can give the copy whatever name you like.
Or of course you could look up www.php.net/rename
The question of what to name it to is more interesting:
$imagedir=opendir('/newsimage');
$highestnum='0000000';
while(false!==($file=readdir($imagedir)))
{
$file=str_replace('.jpg','',$file); //We'll assume we always have JPEGs.
if(strcmp($highestnum,$file)<0)
{
$highestnum=$file;
}
}
//Strip leading zeros that may cause grief (cf. http://www.php.net/manual/en/language.types.integer.php):
$shortnum=preg_replace('/0+/','',$highestnum);
if($shortnum==''){//Oops! stripped all of them!
$shortnum='0';
}
//Get the next number up
$shortnum++;
$newfilename=sprintf('%07d.jpg',$shortnum);