删除mysql中的行并从文件夹中关联

时间:2014-04-15 08:43:58

标签: php mysql

我有管理面板,我可以在数据库中显示删除它们的行。 这是我删除它们的方法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中我存储了图像的路径和名称。

更新:这是正在运行的文件的最终版本 - >从文件夹中删除文件并在DB中记录

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 个答案:

答案 0 :(得分:3)

使用unlink($your_image_path)删除图片