我有一个管理面板,在那里我可以从数据库中删除行。下面是我如何删除它们delete.php
更新
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
$id = $_GET['id'];
$name = "SELECT name FROM images WHERE id=$id";
$name=mysql_fetch_assoc($name);
$name=$name['name'];
if ($stmt = $con->prepare("DELETE FROM images WHERE id = ? LIMIT 1"))
{
$stmt->bind_param("i",$id);
$stmt->execute();
unlink("../upload/" . $name);
$stmt->close();
}
else
{
echo "ERROR: could not prepare SQL statement.";
}
$con->close();
header("Location: images_delete.php");
}
else
{
header("Location: images_delete.php");
}
然后我必须打开'上传'表删除我从mysql删除的图像。当我从mysql中删除那个图片的时候,我怎样才能从文件夹中删除呢?
在mysql中,我存储图像的路径和名称。
更新:这里是正在工作的文件的最终版本->从文件夹中删除文件并在数据库中记录
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
$id = $_GET['id'];
$name = "SELECT * FROM images WHERE id=$id" or die(mysqli_error($con));
$res = mysqli_query($con, $name);
$row = mysqli_fetch_assoc($res);
$name1 = $row['name'];
//print_r($name1);
if ($stmt = $con->prepare("DELETE FROM images WHERE id = ? LIMIT 1"))
{
$stmt->bind_param("i",$id);
$folder = 'C:\wamp\www\upload';
chown($folder,465);
//var_dump($name1);
unlink($_SERVER['DOCUMENT_ROOT'] . "/upload/$name1");
$stmt->execute();
$stmt->close();
}
else
{
echo "ERROR: could not prepare SQL statement.";
}
$con->close();
1条答案
按热度按时间li9yvcax1#
使用
unlink($your_image_path)
删除图像