Deleting images with PHP

Asked

Viewed 92 times

1

I’m working on a personal cloud for my girlfriend because her iCloud is full.

Basically this is what’s making it all work:

<?php
$dirname = "uploads/";
$images = glob($dirname."*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}", GLOB_BRACE);

usort($images, create_function('$b,$a', 'return filemtime($a) - filemtime($b);'));
foreach($images as $image) {

echo '
 <a href="'.$image.'">
 <img class="img-grid" src="'.$image.'" />
 </a>';
}

?>

E é assim que se parece

Everything works perfectly but I need to figure out a way to get a button or something close to the images (or even inside the image) so that it can erase the image as needed.

Remember that she uses mostly by smartphone, having need to be something easy to run on the touchscreen. I also know that the ideal would be to use unlink(), but I don’t know how to make it work. I’m new to PHP.

At first I thought about the solution below, but I accept any idea! (When clicking, pop-up appears OR redirect to a page of the image where it can be deleted)

Click open

  • Your difficulty is in creating the functionality to delete the image or add the delete button in the demonstrated way?

  • Both! I tried several times and unsuccessfully, even ended up deleting the entire uploads directory unintentionally once

  • Since you’re new to PHP, because instead of killing yourself, you don’t put a free image manager on your server, see this one or this one or this one

  • But the intention is to improve my knowledge friend rs

  • You will improve your knowledge using third party library. Much more than doing it all alone without inheriting any knowledge.

  • But anyway I need a user-friendly interface, it’s my girlfriend who’s using, I don’t even need this cloud, this is f*da :/

  • But anyway, to make an exclusion button is very simple, you can even do a mouse while passing the mouse... and put an action on this button. and delete using ajax.

  • Here is an example I did using javascript only.

  • Actually thinking better the delete button on the image/ next to the image would be something impractical, given that it uses only on the smartphone and the images get very small on the screen, which can lead to a miss click. Maybe I have more work than I think.

  • I updated the idea in the post.

  • For now I’ve made an example of the button, as soon as I can answer full. jsfiddle

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.