How to write to a file in Javascript(on server)?
I also need to read the file. And here is my code:
function write()
{
var = true;
if( var = true)
{
//write file
}
}
function read()
{
//read file
}
How to write to a file in Javascript(on server)?
I also need to read the file. And here is my code:
function write()
{
var = true;
if( var = true)
{
//write file
}
}
function read()
{
//read file
}
If I understood your question correctly, you wish to read/write files in the server and your server side language is javascript. If you are using Node, this link : http://nodejs.org/api/fs.html#fs_fs_readfile_filename_encoding_callback provides relevant information on doing the same.
You can read files by doing an AJAX request with possibly a file name or id
You can write the file by getting the data from possibly a input of type text. Assume the input id to be "text"
on the php side just get the post data and write that to the file
If you want Javascript to do the reading or writing, as far as my knowledge goes theres only a HTML5 File API but thats for reading files only I guess.
Writing a file is not a feature of Javascript. In some recent browsers you can already read them, but it's not a good option. The best way is to read it with PHP and get the response with XMLHttpRequest.
JavaScript
PHP