0

I try to delete image in my images directory but still not happen with my image file. I try to use with this code:

<a href=\"../admin/core/de_products.php?id=$row[id]\">Delete</a>

with this function:

<?php
require_once("../inc/con_db.php");

if(isset($_GET["id"]) && $_GET["id"]!="")
{

$image=mysql_query("SELECT * FROM products WHERE id='".$_GET["id"]."'") or die(mysql_error());`

    if(mysql_num_rows($image)>0)
    {
        $row=mysql_fetch_array($image);
        $image_name=$row["img_thumb"];`

        $check=mysql_query("DELETE FROM products WHERE id='".$_GET["id"]."'") or die(mysql_error());

        if($check)
        {
            @unlink("images/products/thumbs/".$image_name);
            echo "Database has been deleted!";
        }
        else
        {
            echo "Oops, there is some problem";
        }
    }   
}
?>
4

1 回答 1

1

您是否在页面或服务器日志中收到任何警告或错误?我建议您从 unlink 前面删除 @ 直到您完成调试此问题,以便您可以实际看到它可能抛出的警告。

您可以尝试检查 .../thumbs/ 目录是否可由您的服务器运行的任何用户写入。或者,如果您像我一样懒惰,可以将其权限设置为 777。要删除文件,您需要对其所在目录的写入权限。

于 2012-09-20T02:39:57.190 回答