Delete thumbnail and regular images from folder using php

I don’t know very much about php, but does anyone know how to delete images and also to download them to the computer when the user selects it?

The images are located in my folder/directory. Also, I want to delete both the thumbnail and the regular image.
images/regular
images/th/thumb_

I’m really new to php so this is still rather confusing. I have seen forums saying to use the unlink function, but I don’t really know how to implement that into my code. Does it go into the upload and resize code? or does it have its own page? If possible, give me an example :slight_smile:

Thank you

First you should probably give us your code so we can understand what you’re trying to do and how you’re getting it done so far.

You say you want to use PHP to delete a file in a directory on your web server?
Here is a simple usage of the unlink() function that accomplishes that:


// delete.php

<?php
unlink('test.html');
?>

For this script, the php file that this code is in must reside in the same folder as the file you want to delete. Let us delete a file called test.html. In this case, whatever directory delete.php and test.html are in, test.html will be deleted from that directory.

Now. Are you trying to delete a file when a user clicks a button or something? Please provide more info so we can further help.

As you say to delete a photo use unlink. Basicaly you need to feed the name and location of the image to delete. This can be done via a form of some sort using direct filename input or a table with check boxs.


// Image name from a form
$delete = 'image to delete';
// Delete the images
unlink("images/$delete");
unlink("images/th/thumb_$delete");

I am not sure how to download an image using php but if the image is open on the screen the user can click on it and use “Save as” ?