I am now getting the "Error writing file" message. In the code I have inserted a comment to show where the message I'm getting comes from.
PHP Code:
<?php
function fileappend($txt, $filename) {
//Open the file
$file = fopen($filename, "a");
/*
//I have commented this below section because it wasn't working
//get its contents
$raw = file_get_contents($filename);
//$raw .= $txt;
$contents = $raw . '//\n' . $txt;
*/
//now write it
$append = fwrite($file, $contents);
if ($append)
echo 'File written!<br />';
else {
//Here's the error message I'm getting:
die('Error writing file!<br />');
}
fclose($file);
}
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
//Check if the username and password are correct
$loggedin = (strtolower($username) == 'username') && ($password == 'password');
if ($loggedin) {
//Get the post to write
$body = $_REQUEST['body'];
//If the login passes, write the new post
fileappend('blog.push(new Post("' . $body . '", new Date("' . $_REQUEST['date'] . '")));', 'blog.js');
} else
//If the login fails, not good
echo "Sorry, login failed.<br />";
?>
Bookmarks