Page 1 of 1
Can files be deleted using a link?
Posted: Wed Nov 09, 2005 10:36 am
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
Posted: Wed Nov 09, 2005 11:14 am
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.
Posted: Wed Nov 09, 2005 11:15 am
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.
Posted: Wed Nov 09, 2005 11:38 am
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.