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

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
Roger22
Forum Newbie
Posts: 8
Joined: Tue Oct 27, 2009 12:31 am

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

Post 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
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

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

Post by Sephern »

I'd add a $_GET parameter, then put the relevant code in an isset.
Roger22
Forum Newbie
Posts: 8
Joined: Tue Oct 27, 2009 12:31 am

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

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post 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...
Post Reply