Jump to content

Delete Image from Folder


ayok

Recommended Posts

Hi,

I have a question. I have some php scripts to upload images and delete it. But if I delete the image I only delete the image's data in the database, and the image still remains in the folder.

 

My question is, how can I remove the image from the image folder?

 

Thank you,

ayok

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.