Log in

View Full Version : fwrite not working



PeterA
07-14-2009, 09:40 PM
Hi guys,

I'm trying to edit a file (specified by the user) from within the ./articles/ directory of the script.

But, it is overwriting it the minute I load it and will not update (giving this error:
Warning: fwrite(): supplied argument is not a valid stream resource
)

Here is my code:

<html>
<head>
<title>Edit Page</title>
<style type="text/css">
body {
font-family: Helvetica, Arial;
}
</style>
<script type="text/javascript" src="http://www.rydgroup.net/editor/ckeditor.js"></script>
</head>

<?php


$pagename = $_GET['pagename'];

$fn = './articles/'.$pagename.'.txt';
$file = fopen($fn, "w+");
$size = filesize($fn);

if($_POST['editor1']) fwrite($fn, $_POST['editor1']);

fclose($file);

$incfile = file_get_contents("$fn");

?>

<form action="" method="post">

<textarea name="editor1">
<?php echo $incfile ?>
</textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>


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

</form>

Anyone have any ideas what is wrong?

Thanks