我写了一个php脚本,其中我编写了查询以从我的数据库中删除特定的选定图像。现在我想删除所有从数据库中删除的图像,并且还想从我的文件夹中删除图像。 在这里我附上我的数据库的图片
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cribsuite";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Query for delete the images from database
$sql = "delete t1
from rr2s4_cma_images t1 JOIN rr2s4_cma_images t2
on t1.matrix_unique_id = t2.matrix_unique_id
and t1.ordering > t2.ordering";
//echo $sql;
$vin = mysql_query($sql);
//echo $sql;
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
?>
答案 0 :(得分:0)
您始终可以使用unlink(file_with_path)
如果要删除已从数据库中删除的特定图像,则需要使用SQL
从数据库中获取图像列表。
您还需要使用glob
从文件夹中获取图片。然后比较图像并删除数据库中不在图像列表中的图像