PDA

View Full Version : Write to a file?



Moh
28-03-2008, 08:52 PM
Does any one know how to write to a file?

So once I click submit, it will replace the file with the new information?

Edit:
Dosnt matter, its easy :)
<?php
$File = "test.asx";
$Handle = fopen($File, 'w');
$Data = "Text";
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);
?>

Robbie
28-03-2008, 08:57 PM
<?php
echo("Done");
$data = "ello"; // Your data here
$file = "file.txt"; // File url here chmod to 777
$lol = fopen("$file", "w");
if (!$lol) {
echo("ERROR");
exit;
}
fputs ($lol,implode,("\n"));
fwrite($lol,"$data");
fclose($lol);
?>

--ss--
28-03-2008, 09:02 PM
A basic and very badly coded one:


<?php
$text = $_POST['text'];
$file = fopen("log.txt","w+") or exit("The file could not be opened");
fputs($file , "$text");
fclose($file);
?>You then will write a simple form to generate the text you want to put into the string to get changed in the log.txt file

<form method="post" action="log.php">
<input type="text" name="text" />
<input type="submit" name="submit" value="Update" />
</form>And if wanted you can display the contents aswell:

<textarea>
<?php echo file_get_contents("log.txt"); ?>
</textarea>The log.txt file must be CHModed to 0777 ;).

Want to hide these adverts? Register an account for free!