how to create txt with js? [closed]

1

And I have a JS that has a function that takes the name of the player, position, position, level, image, etc. I want to save this data in a dB, the user logs in with the account and accesses the data with a JS, to view the information.

Can I do this with a JS and php?

Or I can write to a txt, and capture with JS in the BD folder of the site's host.

There is a way to create a txt with in the site host with pure JS for example creates record le and erases data in txt with JS.

    
asked by anonymous 06.04.2015 / 01:36

2 answers

1

JavaScript is a client-side language and therefore very limited in terms of access to client files. This is for security reasons, to prevent programs from making attacks to the user.

There is a library that writes files via JavaScript and works in modern Browsers. It is based on HTML5 support, which older browsers do not have, and uses the "Save as" that the browser exposes to JavaScript.

Take a look at Github: link
Euma demo here : link

    
06.04.2015 / 08:52
0

Yes, you can do it with Javascript. (Exclusive to IE) I'll explain:

//Cria Objeto ActiveX
var dados = new ActiveXObject(“Scripting.FileSystemObject”);

//Função para gravar o arquivo
function GravaArquivo(arq,texto){
//pasta a ser salvo o arquivo
var pasta=”C:/Documents and Settings/Computador2/Desktop/LerGravartxtcomJS/”;
//se o parametro arq que é o nome do arquivo vier vazio ele salvará o arquivo com o nome “Sem Titulo”
if(arq==””){arq=”Sem Titulo”;}
//carrega o txt
var esc = dados.CreateTextFile(pasta+arq+”.txt”, false);
//escreve o que foi passado no parametro texto que é o texto contido no TextArea
esc.WriteLine(texto);
//fecha o txt
esc.Close();
}
//Função para abrir o arquivo
function AbreArquivo(arq){
//o parametro arq é o endereço do txt
//carrega o txt
var arquivo = dados.OpenTextFile(arq, 1, true);
//varre o arquivo
while(!arquivo.AtEndOfStream){
//escreve o txt no TextArea
document.getElementById(“texto”).value = arquivo.ReadAll();
}
//fecha o txt
arquivo.Close();
}
    
06.04.2015 / 01:41