Can files be deleted using a link?

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!

Moderator: General Moderators

Post Reply
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Can files be deleted using a link?

Post by michlcamp »

Is there a way to delete a file within a directory using a link?

I have a script that will list all the files in a directory and, in the output, I'd like to create a link next to each file that says "Delete This file"

filename1.jpg Delete File
filename2.jpg Delete File
filename3.jpg Delete File
filename4.jpg Delete File

Any help appreciated.
Thanks in advance.
mc
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

ofcourse there is a way. you could link to an external php script that deletes the file, you could use GET or POST.
theres probably a snippet in the PHP manual that shows you the code to delete a file.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, they can.. however, it's suggest to not allow deletions via a standard link, but by having that link perform a submission (post) to a script that can perform the deletion instead.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

feyd wrote:yes, they can.. however, it's suggest to not allow deletions via a standard link, but by having that link perform a submission (post) to a script that can perform the deletion instead.
Maybe we should give a reason why:


say your deletion url is http://127.0.0.1/admin/delete.php?id=56

now only an admin with the correct password could cause the file to be deleted by going to that url, but lets say someone used bbcode on this forum to put an image with that as the source. If an admin were to log into your application, and then visit this forum, when his computer tries to load the image tag is requests the deletion URL. There are other workarounds to using POST, but that has been discussed in great lengths in other threads.
Post Reply