<?php
require_once("cineteca.include");
if(!$conn)
{
die(mysqli_error());
}
$actor_id = $_GET["id"];
$sql = "
select *
FROM
actor a
INNER JOIN
gallery g
on
g.actor_id_fk = a.actor_id
WHERE
a.actor_id=". $actor_id;
$rs = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($rs))
{
$nome= $row ['nome'];
$getIamgeName = $row['photo'];
if(isset($_GET['deleteid']))
{
$createDeletePath = "../image_upload/actor/uploads/$nome ($actor_id)/".$_GET['deleteid'];
$selectSql = "
select * from gallery WHERE actor_id_fk = ".$_GET['id'];
$rsSelect = mysqli_query($conn,$selectSql);
$getRow = mysqli_fetch_assoc($rsSelect);
if(unlink($createDeletePath))
{
$deleteSql = "delete from gallery where gallery_id = ".$_GET['deleteid'];
$rsDelete = mysqli_query($conn, $deleteSql);
if($rsDelete)
{
header('location:gallery_delete.php?success=true');
exit();
}
}
else
{
$errorMsg = "Unable to delete Image";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP remove uploaded file from folder and database</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
</head>
<body>
<div class="container">
<h3 class="text-center">Delete Images</h3>
<div class="row">
<?php
if(isset($errorMsg))
{
?>
<div class="alert alert-danger">
<?php
echo $errorMsg;
unset($errorMsg);
?>
</div>
<?php
}
?>
<?php
if(isset($_GET['success']) && $_GET['success'] == 'true')
{
?>
<div class="alert alert-success">
<?php
echo "Images has been deleted sucessfully";
?>
</div>
<?php
}
?>
<?php
$imgWithPath = "../image_upload/actor/uploads/$nome ($actor_id)/".$row['photo'];
?>
<div class="col-md-12 text-center" style="margin-top:10px">
<img src="<?php echo $imgWithPath ?>" width="100">
<a href="?id=<?php echo $actor_id;?>&deleteid=<?php echo $row["gallery_id"]?>" class="btn btn-primary">Delete image</a>
</div>
<?php
}
?>
</div>
</div>
<script src="../js/bootstrap.min.js"></script>
</body>
</html>