-1

I am looking take in a single string of data using a web form (presumably HTML5), and append that input onto the end of a server-side text file. Is there a way for me to do this using something like Javascript or ActiveX? I know you can use such a form to create a text file and download it to the client (Like discussed here and here ), but I want that file to be saved on the server, rather than the client's machine.

Security will be handled in the form of access controls on the form page itself, so I'm not too worried about code injection, although if there was a relatively easy way to sanitize the inputs, I would include that as well. Also, the contents of this file will not be sensitive in nature, so public exposure is fine.

So for example, could I use something like the code offered here but then add the input to file on the server instead of offering it as a download? If needed, I could also switch to PHP, or other web languages.

Thanks!

DavidB
  • 3
  • 4
  • Could you give us an example of something you've already tried? From what I'm reading, my understanding is that you would like to append a string to the end of an already existing text file and then save it? – Jay Jordan Apr 08 '20 at 18:16
  • 1
    @Jay-Jordan, I previously set up a form which saved its inputs to a MySQL database. That was some time ago, and I since abandoned that and forgot exactly how I did it in the first place. That has been my only semi-successful attempt, since it did actually work. The problem is that I'm trying to pull this data into a program which does not support databases, and for complex reasons, really cannot. Anyway, you understood correctly...this is exactly what I want. I want to be able to have users add a short line of text to file, on a server, without them needing to download, edit, and upload. – DavidB Apr 08 '20 at 21:50
  • Well this could involve multiple technologies. It's hard to give a "blanket" answer that would satisfy everything. I'm not the right guy to give you an answer in php, but I can hopefully provide some guidance. If you provided a input element for a user to enter the string, you could then, through some dom event, trigger an http request (ajax, fetch, etc.) to a server. The server could then take that string and append/prepend that to a text file and save it. It's pretty straight forward. If you need an example of the javascript part, I can help; or if you need an example using c# or java. – Jay Jordan Apr 14 '20 at 15:13
  • Sorry for the late response. Haven't been as active on SO lately. – Jay Jordan Apr 14 '20 at 15:14
  • @Jay-Jordan I would certainly welcome a code example, but I don't want to ask you to do all the work for me. Other than the javascript on the front-end, what kind of code would I need to be running on the server to make this request from the client? – DavidB Apr 14 '20 at 20:42

1 Answers1

0

Is there a way for me to do this using something like Javascript or ActiveX?

Client-side technologies cannot write to files on the server.

You can make an HTTP request. The server-side code that handles that request can write to a file. That server-side code could be written in JavaScript. It could also use ActiveX controls.

Security will be handled in the form of access controls on the form page itself

Attackers don't need to see the form in order to make HTTP requests to the place the form points to. That is just security through obscurity … which isn't security.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Ok, I've never handled this from a server-side before. Do you have any pointers as to where I can start reading up on this? If I did use this method, how could I secure it? – DavidB Apr 08 '20 at 17:06