Hi, I'm trying to create a small script that loads or creates a text file in the /articles directory. However, it is not creating a new file if exists, or updating it. Here is my code to select the file: <form action="admin-ep.php" method="post" name="editpageform"> <p> Page Name:<br /> <input name="pagename" type="text" /></p> <p> <input name="EditPage" type="submit" value="Submit" /></p> Code (php): Here is my code to edit the file: <html> <head> <title>Edit Page :: Powered by rydgroup Club Site</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> <body> <h2> ADMIN AREA</h2> <?php $pagename = $_POST['pagename']; $fn = "./articles/$pagename.txt"; $file = fopen($fn, "w+"); $size = filesize($fn); if($_POST['Update']) fwrite($file, $_POST['editor1']); //$text = fread($file, $size); fclose($file); ?> <form action="<?=$PHP_SELF?>" method="post"> <textarea name="editor1"><?php $file ?>></textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); </script> <input type="submit" value="Update"/> </form> Code (php): What's wrong with it? Thanks
<?php $file = 'people.txt'; // The new person to add to the file $person = "John Smith\n"; // Write the contents to the file, // using the FILE_APPEND flag to append the content to the end of the file // and the LOCK_EX flag to prevent anyone else writing to the file at the same time file_put_contents($file, $person, FILE_APPEND | LOCK_EX); ?> PHP: you can see file_put_contents and file_get_contents
You've got 2 mistakes: remove comments from this line: //$text = fread($file, $size); PHP: like this $text = fread($file, $size); PHP: <textarea name="editor1"><?php $file ?>></textarea> PHP: should be: <textarea name="editor1"><?php echo $text ?>></textarea> PHP: