heres some code i use that works:
// get the existing filenames
$res = mysql_query("select thumb_name,full_name from photos where photo_id=" . $_POST['photo_id']);
$oldpics = mysql_fetch_assoc($res);
// the image thing - how to know to update it?
$newpic = 0;
$thumbname = "";
$fullname = "";
if (!empty($FILES['pic_name']['name']) && is_uploaded_file($FILES['pic_name']['tmp_name'])){
// make the names
$thumbname = "pt" . $FILES['pic_name']['name'];
$fullname = "pf" . $FILES['pic_name']['name'];
// save the thumbnail
if ($_POST['fmt'] == 'P')
resize2file($_FILES['pic_name']['tmp_name'],120,160,"../img/pthumb/" . $thumbname,85);
else
resize2file($_FILES['pic_name']['tmp_name'],160,120,"../img/pthumb/" . $thumbname,85);
// save the full pic
move_uploaded_file($_FILES['pic_name']['tmp_name'],"../img/pfull/" . $fullname);
// signal new pic
$newpic = 1;
}
// now the photo record
$sql = "update photos set caption='" . my_addslashes($POST['caption']) . "',keywords = '" . my_addslashes($POST['keywords']) . "',psection_id = " . $_POST['psection'];
// did they select another pic
if ($newpic == 1)
$sql .= ",thumb_name = '" . $thumbname . "',full_name = '" . $fullname . "',format = '" . $_POST['fmt'] . "'";
$sql .= " where photo_id = " . $_POST['photo_id'];
$res = mysql_query($sql);
if (!$res){
$_SESSION['error_code'] = ERR_UPDATE_FAILED;
header("Location: cms_error.php");
die();
}
// delete the old files
if ($newpic == 1 && $oldpics['full_name'] != $fullname){
unlink("../img/pfull/" . $oldpics['full_name']);
unlink("../img/pthumb/" . $oldpics['thumb_name']);
}