ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

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

2019-10-10 03:23:22  阅读:14  来源: 互联网

标签:php mysql



我有管理面板,在其中显示数据库中具有删除功能的行.
这是我如何删除它们delete.php

UPDATE

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

解决方法:

使用unlink($your_image_path)删除图像



标签:php,mysql

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有