1

I have row that contains (id, name, pic), I can delete this row from the database, but cannot delete the image from the file server.

Below code should delete the image file:

if(isset($_GET["delete"])){

$pi=$_GET["delete"];
$qry="delete from item where id=".$_GET["delete"];
$de = mysqli_query($conn,$qry);

$filetmp = $_FILES["pic"]["tmp_name"];
// $filename = $_FILES["pic"]["name"];
$qr ="SELECT id FROM item where id='$pi'";
$res = mysqli_query($conn,$qr);
while($row = mysqli_fetch_array($res)){
$id = $row["id"];
}
$path = "uploads/$id.jpg";
//move_uploaded_file($filetmp,$path);
$fpath = "images_upload/Uitem/$path";
unlink($fpath); // delete file

}
Blueblazer172
  • 551
  • 2
  • 14
  • 43
Abdulelah
  • 53
  • 1
  • 1
  • 5

1 Answers1

0

you'll have to use the path on your server to delete the image, not the image url. Like

unlink('/var/www/test/'.$fpath);
Alok Bichhwe
  • 172
  • 2
  • 8