2013-04-15 39 views
0

我正在尝试编写脚本来上传脚本以从我的服务器中删除图像。我不断收到错误消息。任何人都可以找到这个代码有问题吗?PHP解除链接保持失败

// 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> 
    <? 
} 
} 
+0

是在db字段中的绝对路径吗?你可能会从不同的位置调用'unlink',所以它不起作用,因为它找不到文件 – Fabio

+0

db字段中的路径是这样的:/gfx/image.png –

+0

,你现在在哪个目录中? – Fabio

回答

1

我猜你的错误是在你的unlink()功能path,正如你所说的实际场就像是/gfx/image.png至极不看我像一个绝对路径,纠正我,如果我错了。

要直接删除file并使用unlink(),脚本应与图像位于同一文件夹中。所以我认为最好将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'])) 
+0

为什么不'/ gfx/image.png'是绝对路径吗? –

+0

它也可能是,你是对的,但我没有从用户那里感受到,而我问他他 – Fabio

+0

我更新它“ht tp://www.mysite.nl/testsite/cms”。$ imageDeletePath ['image ']但它仍然不起作用? –