Jump to content

Edit txt files from 1 php page


El Estrago

Recommended Posts

So I'm working on a php page that can edit a .txt-file.

This is what I'v got so far:

<?php 
if (isset($_POST['submit'])) {  

$stringData = stripslashes($_POST['sf']);  
file_put_contents("huisrekening.txt", $stringData); 

header('Location: quaestor.php?a=update');  

}  
?> 

Huisrekening: 
<form action="" method="post"> 
<textarea name="sf" cols="100" rows="20"> 
<?php 
$theData = file_get_contents("huisrekening.txt"); 
echo $theData;  
?></textarea> 
<br /> 
<input type="submit" name="submit" value="Update" /> 
</form> 

<?php 
if ($_GET['a'] == 'update') { 
echo ''; 

$myFile = "huisrekening.txt"; 
$fh = fopen($myFile, 'r'); 
$theData = fgets($fh); 
fclose($fh); 
echo $theData; 

} 
?>

 

Problem: each time I hit the Update button an extra line appears in the .txt-file. :-(

Does anybody know what I did wrong?

Link to comment
https://forums.phpfreaks.com/topic/237800-edit-txt-files-from-1-php-page/
Share on other sites

I'm just starting out with php. What exactly do you mean by trimming?

 

Edit:

This is what my goal is: a page with data, only one person (with password) is able to edit is via his browser (so without using ftp).

I did play a little bit with Drupal, Wordpress and Joomla, but those CMS are too big and I have a perfect html/css website template (my own ^^) at the moment, don't want to change that.

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.