Hello everyone. I am working on a site that has a backend allowing the client to use a rich text editor to change the content of her pages. The editor page has a form that looks like this:

<form name="edit" method="post" action="processedit.php">
  					<textarea name="editor" id="editor" cols="50" rows="10"> 
						<?php echo $content; ?>
					</textarea>
  					<input type="hidden" name="pathToFile" value="index" />
					<input type="submit" value="Save" />
				</form>

And the action sends the form to the processedit.php shown here:

<?php
$data = $_POST['editor'];
$path = $_POST['pathToFile'];
$file = "includes/" . $path . ".inc";
$Handle = fopen($file, 'w+') or die("can't open file");	
fwrite($Handle, $data);
fclose($Handle);
echo 'Page saved. Click <a href="edit' . $path . '.php">Here</a> to return.'; 
?>

The problem is that if I leave the or die command in, I get the error that the file cannot be opened. If I take out the or die line and echo $path, the path to the file comes through correctly. If I echo $data the text that was there originally comes through, but not any of the changes I made.

Anyone have any ideas as to why the fopen function is not working?

Thanks for all the help!

<form name="edit" method="post" action="processedit.php">

<textarea name="editor" id="editor" cols="40" rows="10">

<?php echo $content; ?>

</textarea>

<input type="hidden" name="pathToFile" value="banlist" />

<input type="submit" value="Save" />

</form>


i am currently trying to figure out the logic, this is Cyrus, and i believe i found the problem of the or die, i have it working with it, i created a file includes and added a banlist.txt changed the .inc extension and just used a plain text file, i was able to write copy code in box and save , and it saved to the general location on webserver. please make sure that the file location is writeable where your saving. here is the the processedit script

<?php

$data = $_POST;

$path = $_POST;

$file = "includes/" . $path . ".txt";

$Handle = fopen($file, 'w+')or die("can't open file");

fwrite($Handle, $data);

fclose($Handle);

echo 'Page saved. Click <a href="' . $path . '.php">Here</a> to return.';

echo $data;

echo $file;

?>

This question has already been answered. Start a new discussion instead.