met php een txt bestand leeg maken

Gestart doorRohimma7 reacties23 weergaven

8 berichten · pagina 1 van 1

Rohimma

Lid · Topicstarter

Berichten
1.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
hoe kan ik met behulp van php een tekst bestand leeg maken? (via een button)
de buttom moet in gegevens.php komen

dit stuk script is voor het invullen:
(index.php)
Spoiler tonen
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhttm11/DTD/xhtm11-strict.dtd">
<html>
<head>
</head>
<body>
<h3>test 1</h3>
<form action="opslaan.php" method="post">
Uw naam : &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp        <input type="text" name="naam"><br>
Uw achternaam :                         <input type="text" name="achternaam" width="300" height="400"><br>
Uw e-mail :&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp        <input type="text" name="email"><br><br>
hier uw vraag :        <br>
<TEXTAREA NAME="vraag" ROWS="10" COLS="50"></TEXTAREA><br><br>
<input type="submit" value="versturen">
</form>
</body>
</html>
dit stukje slaat het op in het txt bestand:
(opslaan.php)
Spoiler tonen
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhttm11/DTD/xhtm11-strict.dtd">
<html>
<head>
</head>
<body>
<h3>gegevens verwerkt</h3>
[COLOR= #0000BB]<?php   
$naam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"naam"[/COLOR][COLOR= #007700]];[/COLOR]   
[COLOR= #0000BB]$achternaam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"achternaam"[/COLOR][COLOR= #007700]];[/COLOR]   
[COLOR= #0000BB]$email[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"email"[/COLOR][COLOR= #007700]];[/COLOR]
[COLOR= #0000BB]$vraag[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"vraag"[/COLOR][COLOR= #007700]];[/COLOR]

[COLOR= #0000BB]$data[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"gegevens.txt"[/COLOR][COLOR= #007700];[/COLOR]   
[COLOR= #0000BB]$file[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/fopen"]fopen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$data[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"a"[/COLOR][COLOR= #007700]);[/COLOR]   
[URL="http://www.php.net/fputs"]fputs[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<h1>.</h1><br> naam : $naam <br>achternaam : $achternaam<br> e-mail : $email <br> vraag : <br> $vraag <br><br>"[/COLOR][COLOR= #007700]);[/COLOR]   
[URL="http://www.php.net/fclose"]fclose[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]);[/COLOR]   
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"uw vraag is verstuurd!"[/COLOR][COLOR= #007700];[/COLOR]   
?>  

</body>
</html >
dit stuk script haalt de gegevens uit het txt bestand:
(gegevens.php)
Spoiler tonen
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhttm11/DTD/xhtm11-strict.dtd">
<html>
<head>
</head>
<body>
<h3>gegevens</h3>
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"gegevens.txt"[/COLOR][COLOR= #007700]);[/COLOR] 
?>
</body>
</html >
0
Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhttm11/DTD/xhtm11-strict.dtd">
<html>
<head>
</head>
<body>
<h3>gegevens</h3>
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]empty[/COLOR][COLOR= #007700]])) {[/COLOR]

[COLOR= #0000BB]$handle[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/fopen"]fopen[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"gegevens.txt"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"w"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$close[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/fclose"]fclose[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$handle[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000] bestand leeg gemaakt[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"gegevens.txt"[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<form action="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]PHP_SELF[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" method="post">
<input type="submit" name="empty" value="leegmaken" />
</form>[/COLOR][COLOR= #007700];
}[/COLOR]

?>
</body>
</html >


Als je fopen met w erachter zet haalt hij heel het bestand leeg en zet de cursor bovenaan.
Als je er niks in zet blijft hij uiteraard leeg.
0
Rohimma

Lid · Topicstarter

Berichten
1.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
als je die pagina vernieuwd is alles weg....

ik heb al een idee om het op te lossen weet iemand hoe je in php een code kan maken zodat je na 10 sec naar de volgende pagina gaat?
0
Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rohimma schreef:
als je die pagina vernieuwd is alles weg....

ik heb al een idee om het op te lossen weet iemand hoe je in php een code kan maken zodat je na 10 sec naar de volgende pagina gaat?
met de header refresh (ff opzoeken op google met mobiel ist iritant typen)

En dat als je refreshed komt doordat de bitton nog niet aanwezig was als je momentje hebt fix ik dat
0
Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<meta http-equiv="refresh" content="10;url=website.nl">[/COLOR][COLOR= #007700];[/COLOR]
?>


zoiets?
0
Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Marjolein schreef:
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<meta http-equiv="refresh" content="10;url=website.nl">[/COLOR][COLOR= #007700];[/COLOR]
?>


zoiets?
Kan ook indd
@TS.
Code bij mijn eerste reactie is aangepast met een button
0
Berichten
7.757
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rohimma schreef:
als je die pagina vernieuwd is alles weg....

ik heb al een idee om het op te lossen weet iemand hoe je in php een code kan maken zodat je na 10 sec naar de volgende pagina gaat?
robsdomein.nl wink
0
Rohimma

Lid · Topicstarter

Berichten
1.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
ik heb al wat gekregen van een vriend van me en daar me is het ook gelukt.

toch bedankt allemaal thumbsup
Afbeelding
thumbsup
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren