我有一个用于将图像上传到服务器的 PHP 函数,
但我很困惑,我想给当前上传的文件一个唯一的 md5 名称。这是我的代码:
if ((getimagesize($_FILES['user_image']['tmp_name']) >0) && $_FILES['user_image']['size'] > 0 && ($_FILES['user_image']['size'] < 1048576)){
$uploaddir = DIR.'/images/';
$uploadfile = $uploaddir . basename($_FILES['user_image']['name']);
move_uploaded_file($_FILES['user_image']['tmp_name'], $uploadfile);
// check if user have already uploaded an image, then delete
//it before uploading new one
$old_file = db_user_image($user, 'image');
if (strlen($old_file)){
$delete = $uploaddir.$old_file;
if (file_exists($delete))
unlink ($delete);
}
db_save_user_image($user, 'image', $_FILES['user_image']['name']) ;
}
请告诉我如何为这些文件提供唯一的 md5 名称。