Clearing content of text file using php

Subho Halder picture Subho Halder · Jul 2, 2009 · Viewed 118k times · Source

I have a filelist.txt file and I created a file called clear.php to clear the content of filelist.

I put a button in index.html to call clear.php to clear the file.

Can anyone help me out regarding what PHP code I should write in clear.php?

How to code a button to call clear.php and then return back to index.html showing the result that it has been cleared?

Answer

Andy E picture Andy E · Jul 2, 2009
file_put_contents("filelist.txt", "");

You can redirect by using the header() function to modify the Location header.