![]() |
|
| *SoulEyes Photography>>>Photo Gallery |
PHP delete image file.? |
Okay here is my problem. I have an image gallery and would like the admin to be able to delete certain photos without having to connect to the ftp server. how can I attatch unlink() to a button or link. so when they click on the button it deletes the file? The following code is insecure; make sure your admin is somehow authenticated, because anyone using this script will be able to delete your images. This code also assumes all images are in the same directory. Under each image, have a link that will redirect the user to a file named imagedelete.php?imgid=ID, where ID is the name of the image to be deleted. imagedelete.php: <? if(!isset($_GET['imgid']) || $_GET['imgid'] == '') { die('No get parameter!'); } $path = "/physical/path/to/image/folde... $imgfile = $path . $_GET['imgid']; if(!is_file($imgfile)) { die('No such image file: ' . $imgfile); } if(unlink($imgfile)) { header('Location: previouspage.php'); } else { die('Cannot delete file: ' $imgfile); } ?> |
| Tags |
| Photography School Photography Magazine Photography Jobs Photography Equipment Photography Courses Photo Gallery Photo Essays Art Gallery Wedding Photography Stock Photography |
Photography Categories--Copyright/IP Policy--Contact Webmaster |