kempstead Posted June 16, 2011 Share Posted June 16, 2011 I am making a basic cms for a gallery script, I have a list of thumbnails (generated from an ajax script) with a delete link next to each thumb like so... <ul class="thumb-list"> <li><img src="images/thumbs/000000001.jpg"><a href="delete.php?file=000000001.jpg">delete</a></li> <li><img src="images/thumbs/000000002.jpg"><a href="delete.php?file=000000002.jpg">delete</a></li> etc... </ul> I have found this script which I think is what I need to use?? <?php $filename = "myfile.txt"; unlink($filename); ?> ideally what I want to do is have the user click the delete link, a prompt displays - "are you sure?" the thumb and the large image are deleted and the list of thumbnails is reloaded. the thumbs and the large images have the same file name but are in different folders.. /images - large images /images/thumbs - thumbnails any pointers appreciated Quote Link to comment https://forums.phpfreaks.com/topic/239503-noob-unlink-basics/ Share on other sites More sharing options...
mikesta707 Posted June 16, 2011 Share Posted June 16, 2011 If you want some sort of prompt you will probably need Javascript. In fact what you described you seem to want to accomplish without having to refresh the page. If so you are going to need to use AJAX for this. If you are unfamiliar with AJAX/Javascript or how it can alter the HTML DOM you have some reading to do. I personally suggest using the Jquery library if you are up to learning about it. Makes developing these kinds of things much easier. But to address the first part of your question. With your links, youare sending a get variable. This variable is called file, and can be reached via the $_GET super global. Combining this with the second snippet you posted, you can do something like //this is delete.php $filename = $_GET['file']; unlink($filename); Note: this doesn't validate or sanitize your $_GET['file'] variable. Now we have to address the fact that you have images stored in an image directory, and you have two images to delete (one in /images and one in images/thumbnail) we address this with the following $filename = $_GET['file']; $img = "images/$filename"; $thumb = "images/thumbnails/$filename"; unlink(img); unlink($thumb); Again, I do not sanitize or validate the $_GET data. You must remember to do this, especially if you are deleting files. How, hooking this simple script up with AJAX is something beyond the scope of a simple topic post if you don't know anything about ajax/javascript. I suggest doing a few google searches on AJAX/Javascript of Jquery if you feel up to it Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/239503-noob-unlink-basics/#findComment-1230307 Share on other sites More sharing options...
kempstead Posted June 16, 2011 Author Share Posted June 16, 2011 thanks, that helps a lot. I'll give it a go.. you'll probly be hearing from me soon! Quote Link to comment https://forums.phpfreaks.com/topic/239503-noob-unlink-basics/#findComment-1230312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.