Hi there…
I was looking (since I’m definately an early beginner in PHP) for a simple script to edit a text-file online, using a textarea. I found some php-scripts, none worked… here’s an example of what I tried:
<?php
if ($submit) {
$fp = fopen(“data.txt”, “w”);
fwrite($fp, stripslashes($newdata));
fclose($fp);
}
$fp = fopen(“data.txt”, “r”);
while (!feof($fp)) {
$data .= fgets($fp, 4096);
}
fclose($fp);
?>
<html>
<head>
<title>Edit</title>
</head>
<body>
<form action=”<? print $PHP_SELF; ?>” method=”post”>
<textarea name=”newdata” rows=”50″ cols=”100″>
<?
print $data;
?>
</textarea>
<br>
<input type=”submit” name=”submit” value=”Save”>
</form>
</body>
</html>
It didn’t return an error, but simply reloaded data.txt, doing nothing like saving the data at all. Interestingly I experienced the same with a different script. The script is placed in protected directory, together with some scripts to upload files, also written in php. Uploading works just fine. I cannot figure out why it does not work. As said: me noob *grunt
I would gladly accept any advice or code that’ll do the job. Can’t be that complicated… Thanks.