| |||||||||||
| |||||||||||
Delete specific file in directory. Posted by TedH (TedH), 14 February 2005 I've got a blog script that can create files etc. but has no delete function. So I want to put together a little script to do that.I can list the files fine. I know I can delete one file with unlink by typing in the name. See below: --------- Files: one.txt two.txt three.txt --------- Code:
this leaves two.txt and three.txt files and deletes one.txt okay. --------- How do I make the link delete the particular file? I've spent two days searching all over the place and there seems to be a concerted effort by some programmers and tutors to see how many zillions of files they can delete at once (it's almost laughable), but not just one file. Hope you can help, thanks - Ted Posted by admin (Graham Ellis), 15 February 2005 You'll need to set up the link as it it was a form.e.g. <a href=/cgi-bin/demo.pl?file=abc.txt>abc.txt</a> Then in the code ($fntd) = ($ENV{QUERY_STRING} =~ /file=(.*)/); unlink $fntd; I am out of the office and have NOT tested these lines - please read and proceed with care! You'll also need to add a directory path unless you're trying to delete a file in the cgi-bin directory (which I hope you are NOT!) Posted by TedH (TedH), 15 February 2005 Thanks Graham. It is inside the cgi bin, inside a password protected admin script. I was thinking about the implications, and will probably even password protect the deletion script as well. I've only had one request to have this option and may just leave it off the final version. At least I know how to do it now so have a basis to work from. So where are you now? Some warm and sunny again? Posted by admin (Graham Ellis), 16 February 2005 on 02/15/05 at 22:45:31, TedH wrote:
Freezing cold Belgium ... motorway service area on my way back from Munchen to Melksham. If only places with names that start with the same letter were also PHYSICALLY close to each other ... This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |