Jump to content

[SOLVED] Help with File Editing.


snowman15

Recommended Posts

I'm pretty new at php but please give me as much feedback as possible.

 

What I'm trying to create: as part of a learning experience, I'm trying to create a page(text.html) with a form that you can type in a string and then press submit. This submit button uses text2.php to take the string and change testing.txt to whatever the string was. Then i want it to print out whatever testing.txt IS (after it was changed by the form)

 

Heres what i have,

 

text.html


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="text2.php" method="post"> 
<label for="words">words:</label> <input name="words" type="text" /> 
<input type="submit" value="submit" name="submit"/>
</body>
</html>

text2.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
$myFile = "testing.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_GET["words"];
fwrite($fh, $stringData);
fclose($fh);
myFile = "testing.txt";
$fh = fopen($myFile, 'r') or die("can't open file");
$theData = fread($fh, filesize($myFile));
echo $theData;
fclose($fh);
?>
</body>
</html>

 

 

 

 

 

 

Can someone please help me understand what I'm doing :).

Link to comment
https://forums.phpfreaks.com/topic/56673-solved-help-with-file-editing/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.