Javascript and saving information to file - javascript

With AJAXs help it's posible to load data from file, but is it possible to save a value of string variable to file? I want to hold data in file with .txt extension and load it when I will need it.

You will need a server side. Assuming you do, send the data back and forth via GET/POST, and edit/save it from the server side. Unless you want the user to pick the file themselves, you can use the FileReader js object with . Otherwise, for security reasons, you cannot. That would give your system access to any user's home directories on their machine.

Related

How to understand website is sending uploaded files to its server?

How can I understand uploaded files are permanently stored in the website's server?
For example, how can I understand when I uploaded my PDF file to this website (https://smallpdf.com/pdf-to-jpg) whether its also saves my file to its server?
If you are referring to a third party server that you have no control over there is no programmatic way of determining if they are in fact storing your pdfs permanently.
They might have a Terms and Conditions page where they set out the terms and conditions of using their service.
Alternatively if it concerns you try to find a site that makes it clear that they do not store your files permanently.

Write a file on local disk from web app (ReactJS)

I'm developing a web app using ReactJS and trying to create a txt file with a number in it on the local storage, c:\temp for example.
Is it possible to do it without keep asking the user for his approval (dialog)?
Thanks
localStorage is a browser API and not an arbitrary file on the user's disk. If you are going to use it, then there is a handy React hook for it.
You can't write to arbitrary files on the user's disk, although you can generate a download from in-memory data. This may be saved to the user's download folder or may prompt a SaveAs dialog (you can't control which).
If you want to store data on the server then you can make HTTP requests to it (i.e. use Ajax) and write a web service to process those requests.

How can I constantly check if a file is added in a folder?

I have a server that receives .txt files from the client throught cURL. It is then moved to a designated folder. Those .txt files have different names, according to client's ip address.
ex. 192.168.5.n.txt (n=1 to 40)
How can I check files in that folder and return something to indicate that a new file has been added without reloading the page, also without being redundant? I am new to js, do I need Ajax for this?
Thank you.
Edit: I need to return something just in the web page (ex. print $ipaddresstxt. "has been added";) not to the client itself.
More like WebSockets, since the thing you want to detect is server side, and the server has no way to send an HTTP request to the client. You can create a WebSocket connection between the server and the client, and send messages both ways, whenever you need to.

Modifying Text file in javascript

I need to have data written to a text file in javascript. I want it to write a username and password to the text file and create a new line every time. Here is my code http://pastebin.com/24Tvdemu.
Can anyone help this has had me stumped for ages.
As Javascript in html is a client side language, you will need to send the files to the server, and save there the file. Anyway, you can prompt the user to save the file in their local machine, but it´s not usefull at least you really need that for any reason.
Check this answer Javascript: Create and save file
Some suggestions for this -
If you are trying to write a file on client machine, You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write file.
If you are trying to save it on your server then simply pass on the text data to your server and execute the file writing code using some server side language.
To store some information on the client side that is considerably small, you can go for cookies.
Using the HTML5 API for Local Storage.
More details : Is it possible to write data to file using only JavaScript?

Javascript to read/write files on the client side

i need make a javascript code that reads a file from the client computer, specified by the user, something like an upload form but to be only processed by javascript, no server needed. And after processing the data, i need to give the user a file to download containing the processed data.
is there a way to do so? i think it's something about html5, not sure.
i'm new to javascript.

Categories