0

我正在尝试编写脚本来上传脚本以从我的服务器中删除图像。我不断收到错误消息。谁能发现这段代码有什么问题?

// Delete image
if(isset($_GET['deleteImg']) && !empty($_GET['deleteImg']) && $_GET['deleteImg'] == true)
{
 // Get imagepath from database
 $result = mysql_query("SELECT image FROM frankkluytmans WHERE id=$id");
 $imageDeletePath = mysql_fetch_assoc($result);

 // Delete image from server
 if(unlink($imageDeletePath['image']))
 {
    // Continue if image has been reset in database
    if(mysql_query("UPDATE frankkluytmans SET `image`='' WHERE id=$id")){
        // once deleted, redirect back to the view page
        header("Location: index.php"); 
    }
 }
 else
 {
    ?>
    <script type="text/javascript">
        window.alert('This image could not be deleted.';
    </script>
    <?
 }
}
4

1 回答 1

1

我猜你的错误出在path你的unlink()函数中,正如你所说的那样,实际字段/gfx/image.png在我看来并不像绝对路径,如果我错了,请纠正我。

要删除fileunlink()直接使用,您的脚本应与图像位于同一文件夹中。所以我认为最好absolute path为您的条目设置一个

$path_abs = ' /customers/d/8/e/frankkluytmans.nl/httpd.www/testsite/cms'; //is the `gfx` folder inside `cms` folder? if it is this will work otherwise you have to change
if(unlink($path_abs . $imageDeletePath['image']))
于 2013-04-15T14:01:46.267 回答