Page 1 of 1

delete content of a .txt file using <a href..?

Posted: Mon Nov 30, 2009 6:56 am
by Roger22
Hello,

How can i write a html <a href..> and when i click it, a content of a .txt file should be erased?
I tried with

Code: Select all

 
<a href="$fp = fopen("in.txt", w); fclose($fp);">Sterge continut fisier intrare</a>
 
But each time the page is loaded, the content is erased. So not when i click on that link
Please help.

Thanks

Re: delete content of a .txt file using <a href..?

Posted: Mon Nov 30, 2009 7:11 am
by Sephern
I'd add a $_GET parameter, then put the relevant code in an isset.

Re: delete content of a .txt file using <a href..?

Posted: Mon Nov 30, 2009 7:26 am
by Roger22
Sephern wrote:I'd add a $_GET parameter, then put the relevant code in an isset.
hmm.. and how should this be done? i need another php page for this?

Re: delete content of a .txt file using <a href..?

Posted: Mon Nov 30, 2009 9:26 am
by jackpf

Code: Select all

if(!isset($_GET['delete']))
{
    echo '<a href="'.htmlentities($_SERVER['PHP_SELF']).'?delete=1">click</a>';
}
else
{
    //....delete file...
}
Something like that? You might want to incorporate some security into that though...