<?php

include '../koneksi.php';

$data = json_decode(
file_get_contents("php://input"),
true
);

$id = $data['id'];

$foto = '';

$getData = mysqli_query(

    $conn,

    "SELECT foto
    FROM spbu
    WHERE id='$id'"

);

if($row = mysqli_fetch_assoc($getData)){

    $foto = $row['foto'];

}

if(!empty($foto) && file_exists('../uploads/spbu/' . $foto)){
    unlink('../uploads/spbu/' . $foto);
}

$query = mysqli_query(
$conn,
"DELETE FROM spbu WHERE id='$id'"
);

if($query){

    echo json_encode([
        'status'=>'success'
    ]);

}else{

    echo json_encode([
        'status'=>'error'
    ]);

}