当用户上传一张照片时,它会检查他们是否已经有一张照片;如果他们这样做,我希望它删除旧的(可能有任何扩展名),然后放入新的。有没有办法在不从数据库中获取旧扩展的情况下做到这一点?目前的代码:
$del = $members->prepare("insert into profiles(userid, path, width, height, type, rtu, ext) values(?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE path = ?, width = ?, height = ?, type = ?, rtu = ?, ext = ?, time = NOW()");
$del->bind_param('sssssssssssss', $_SESSION['token'], $title, $file_info[0], $file_info[1], $file_info[2], $rh, $extension,
$title, $file_info[0], $file_info[1], $file_info[2], $rh, $extension);
$del->execute();
$new_file_name = "bb-x".$_SESSION['token'].".".$extension;
if ($del->affected_rows > 0) {
unlink('profiles/bb-x62'<any extension>);
}
$move_file = move_uploaded_file($file['tmp_name'], $upload_image_to_folder.$new_file_name);