Jump to content

Delete Image from Folder


ayok

Recommended Posts

Hi,

I have difficulty to set up the code.

What I try to do is to unlink 2 images (same name) in different folder.

This is my delete.php

<?php

include "../dbconnect.php";
$delete="DELETE from product WHERE id='$id'";
$result=mysql_query($delete);

if($result)
{
header("location:index.php");
}
else
{
echo "Delete process failed";
    echo "<a href=index.php>Try again</a><br>";
    echo "<a href=logout.php>Logout</a><BR>";
}

?>

 

I've tried to add this code:

$image = "SELECT image FROM products WHERE id = '$id'";
unlink('images/$image);
unlink('images/thumbnail/$image);

 

But it doesn't work.

 

Could anybody help me?

 

Thanks,

ayok

But

Silly question, but are you getting the 'image' name before deleting the entry, e.g. why didn't you just show the new code? After that check permissions, (e.g. if you created the images you should be able to delete them!)

refs:

http://us3.php.net/manual/en/function.fstat.php, see 'mode'

http://us3.php.net/manual/en/function.chmod.php

All right,

I can now unlink the image files from the image folder in localhost. But when I test it on web server, i keep getting this error:

Warning: unlink() [function.unlink]: http does not allow unlinking in /home/mywebcom/HTML/products/admin/delete.php on line 8

I even set the permission to 777, but i still get this error. How can I solve this?

 

Thank you,

ayok

But it's kind of weird, because i made an upload script where I can put an original image, then create two smaller images in different folders, and then in the same script, I am able to unlink the original image from the folder. So how come I couldn't unlink those two smaller images?

 

thanks,

ayok

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.