PHP: Usuń plik z dowolnym rozszerzeniem?
Gdy użytkownik przesyła zdjęcie, sprawdza, czy już je ma; a jeśli to zrobię, chcę, aby usunął stary (który mógł mieć dowolne rozszerzenie), a następnie umieścił nowy. Czy można to zrobić bez pobierania starego rozszerzenia z bazy danych? Kod w tej chwili:
$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);