Hi!
I am in real need of help!
When visitors have filled out a form on the website the result is sent to a .txt-file.
Is it possible to clear/delete the formresults in the textfile without accessing the file through FTP. Can I clear the results "online"?
Somebody please help me! 🙁
Thanks!
You can delete the file when you've finished with with [man]unlink[/man]
I do not want to delete the file itself...just clear it from content, make it empty. Kind of resetting the file.
Thanks anyway!
More ideas?
See this
Hi again!
I want the file to be cleared manually, for example when i click on a button or something...is this possible??
Yes. Put the code
$fp = fopen("$file", "w"); // open file for write fputs($fp,''); // write empty string fclose($fp);
in a script that gets called when you click on a button or something
hth
Shall i put the code into the formresultsfile? Or do i need to make a php-page with this code that calls for the resultspage?
I a real newbie in php...
Maybe worth mentioning is that i use a phpscript called Phorm JR!
I.ve attached a php page that should do it for you
Rename it to remove the .txt from the end.
Call the page when you want to clear the file.
You are a god!
One prob though...i get an error message:
"Parse error: parse error in ../test/test/clearfile.phtml on line 12"
Just a mere mortal 😉
I forgot the ; at the end of the line
Better but...error in URL when i clicked the button:
http://www.../test/test/<?clearbutton=Clear+results+file
Looks like <?=$_SERVER[PHP_SELF]?> did not work.
May be the short tags and the '=' so try
<php echo $_SERVER[PHP_SELF] ?>.
If that doesn't do it, hard code the name of this script instead
ie
<form action="clearfile.phtml" ......
Thanks for all the help Barand! 😃
You rock!
Damn! Have tried different codes but obviously i´m not that good in coding!
Anyone know how to continue this:
"<form action="clearfile.phtml""
...i don´t have a clue! 🙁
<form action="clearfile.phtml" method="get">
Nothing happens...
Now i do get to the textfile when i puch the button but nothing happens to the file when it is supposed to clear the content.
<?php
if ($_GET['clearbutton']) { $file = "http://www..se/test/registreringar.txt"; // edit this line to give correct path and filename $fp = fopen("$file", "w"); if ($fp) { fputs($fp,''); fclose($fp); exit ("Your text file has been cleared"); } else { exit ("Error opening file"); } } ?> <html> <!-- Creation date: 28/05/03 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Clear results</title> <meta name="Author" content="Barry Andrew"> <meta name="Generator" content="AceHTML 4 Pro"> </head> <body> <h3>Clear Form results file</h3><hr color="#0000ff"> <form action="http://www..se/test/registreringar.txt" method="get"> <input type="submit" name="clearbutton" value="Clear results file">
</form>
</body> </html>
The form action, 5 lines from the end, needs to be THE SAME NAME as this script, so that it calls itself.
<form action="clearfile.phtml " method="get">
That's why I put that name in my 2 previous posts.:rolleyes:
ok...I saw that. But it just won´t work! I have tried every possible combination without any luck!
Maybe it is´nt supposed to be...
Thanks anyway Barand, you have helped me alot! 😃 you´re the king!
Try putting the drive path instead of a url in second line
eg $file = "c:/..../test/registreringar.txt"; // edit this line to give correct path and filename
or (if linux)
$file = "/home/..../test/registreringar.txt"; // edit this line to give correct path and filename
Did not work!