Need to unlink image from folder when updating in PHP

59 Views Asked by At

I am working with php on my localhost server. I want to unlink the image from my server folder whenever I change the image when edit. The picture is changing when I update but the past picture stays in folder.

if (isset($_POST['update'])) {
  $image          = $_FILES['image']['name'];
  $image_tmp      = $_FILES['image']['tmp_name'];

  if (!empty($image)) {
    $del_is = $_GET['deleteUser'];
    $sql = "SELECT * FROM users WHERE id = '$del_is'";
    $del_user = mysqli_query($db, $sql);

    while ($row = mysqli_fetch_assoc($del_user)) {
      $user_image = $row['image'];
    }
    unlink("dist/img/users/$user_image");
}
0

There are 0 best solutions below