Page 1 of 1

Problem with file editor

Posted: Thu Dec 09, 2010 8:22 am
by Regicollis
I'm currently working on a project where the user on a website should have the possibility of editing multiple txt-files from the website.

I would like to have one single edit-page with three forms that edit three .txt-files.

I've made a simple editor and it works fine for just one file. But when I try to make more than one edit-form on the page, the contents of each form is the same as the content of the first form. It is as if the variables are not redefined.

You can see the editor-page here:

http://rasmusk.wid.ots.dk/projekter/kog ... ermenu.php

The PHP-code for each form is:

Code: Select all

            <?php 
				$fn = "menukort/supper.txt"; 
				
				if (isset($_POST['content'])) 
				{ 
					$content = stripslashes($_POST['content']); 
					$fp = fopen($fn,"w") or die ("Error opening file in write mode!"); 
					fputs($fp,$content); 
					fclose($fp) or die ("Error closing file!"); 
				} 
			?> 
			
			<form action="<?php echo $_SERVER["PHP_SELF"]."?gemt=1" ?>" method="post"> 
				<textarea class="redigermenu" rows="<?php echo count(file($fn));?>" name="content"><?php readfile($fn); ?></textarea> 
				<input type="submit" value="Gem &aelig;ndringer">  
			</form>


Re: Problem with file editor

Posted: Thu Dec 09, 2010 9:55 am
by Regicollis
I've got the PHP to load the correct values into the textareas now by resetting the variables $fn and $fp. This is a good first step. However the "save" function doesn't work as it should yet. When I save the changes to one .txt file in the editor it overwrites the values of the other files with those of the one I would like to save. So I end up with three identical files instead of what I would like.

How do I get the PHP to write the changes to only one of the files?