PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
if(isset($_GET['file'])){
unlink($_GET['file']);
echo "File removed, go back and refresh the page.";
} else {
echo "Nope, try again. Might be premission problem";
}
?>
If the statement works and the file exists, the file is removed. If the file is missing or not readable the else does not work...
Warning: unlink(xxxx.jpg) [function.unlink]: No such file or directory in /xxx/xxx/xx/removefile.php on line 3
File removed, go back and refresh the page.
That should be pretty secure. The only thing I can think of is someone deleting a logo or background image or something. I imagine the images you want to be able to delete are within a specific folder, or a set of specific folders? I would also make sure that $image is pointing to a folder you expect it to.
You're php script is not in the same folder as the images, is it? If not then basename is not going to work. How are the images stored, are they all in the same folder?
If so, I would just pass the name of the file into the script, without a path or .jpg, eg. image1.
I would check that the get variable is alphanumeric, maybe also accept . or - or _ depending on how you're doing things.
Then check if (SOMEPATH . clean get var . ".jpg") exists.
Then i would unset (SOMEPATH . clean get var . ".jpg").