本文介绍了从文件夹中删除mysql中与关联的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有管理面板,在这里我可以显示数据库中的行并可以删除它们.这是我删除它们的方法delete.php

I have admin panel where I show rows from database with ability to delete them. Here is how I delete them 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删除该图像时也要从文件夹中删除该怎么办?

Then I must open 'Upload' form to delete the image which I deleted from mysql. How can I make when I delete that image from mysql also to delete from folder?

在mysql中,我存储图像的路径和名称.

In mysql I store path and name of the image.

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

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();

推荐答案

使用unlink($your_image_path)删除图片

这篇关于从文件夹中删除mysql中与关联的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 23:04