I am trying to attempt to give users the ability to write a text file to a directory on the website's host server. A usage case would look like:
- User visits www.example.com/createtext
- User types in a text bot what they would want to be saved, "Hello" for example
- The server that the website is hosted on creates a text file in one of it's directories.
- On the server, there is now a text file in C:/somedirectory/dailytexts/ with "Hello" written inside of it
I have currently written a simple page with a form that will take in text information and save it to a text file with the name of the current date.
<script language="Javascript">
var time = new Date();
var formattedTime = time.toLocaleTimeString();
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' +
encodeURIComponent(text));
pom.setAttribute('download', formattedTime);
pom.style.display = 'none';
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom);
}
</script>
<form id="form" class="topBefore" onsubmit="download(this['name'].value, this['text'].value)">
<textarea id="message" type="text" placeholder="Hello" name="text"></textarea>
<input id="submit" type="submit" value="Download Text File">
</form>
This simply downloads the text file to the user's computer. Instead, I would like the file to be created on the host machine.
Is there anyway to do this? In particular, with just JavaScript or Java. But if it has to be done with something like PHP then that would work too.