Javascript - create text file on website

前端 未结 5 668
庸人自扰
庸人自扰 2021-01-29 07:39

So I have a web page, and I would like to programaticly create a text file (lets say it has the words \'hello, I am a text file\' in it) on a new directory on my website. The pr

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 07:50

    The short answer to your question is no.

    The long answer is that you have the following alternatives:

    • Use a form on the Browser end, send the data back to the server, and then use a server-side language such as PHP to receive and save the data. No JavaScript required, but you do need server-side programming.
    • You can make the process more immediate by using JavaScript on the browser end to send data back to the server. This is called Ajax. You will still need server side processing, though.

    Note that it is probably a very bad idea to simple accept user data and save it directly. There are two things you should consider in your development:

    • Always filter the incoming data against the possibility of receiving and accepting carefully crafted malicious data.
    • Consider storing the data in a database. Apart from being easier to manage (you don’t have to worry about filenames, for example), they can do less damage there.

提交回复
热议问题