简体   繁体   中英

Javascript save variable to .txt file on server and overwrite the.txt content

I've been browsing this website and the only answers I found were for saving the variable on client side (ie using Download atribute). In PHP, I've done this:

<?php
$tracktitle = "test";
$location = fopen("textfile.txt","w+");
fwrite ($location, $tracktitle);
fclose($location);
?>

What is the javascript equivalent of this? I want the content of textfile.txt to be deleted/replaced with the actual variable. Let's say var tracktitle = "test";

I want to get some text from an HTTP page and store it in a .txt file (on FTP) then load the .txt content on an HTTPS website. I will use chronjob to schedule this to run every 5 seconds.

There is no equivalent, at least in how you're asking. Javascript is client-side; it cannot directly write to a file on a server (unless you're talking about Node, which it doesn't seem like you are). To have Javascript write a file, at best it can make a request to your server side tech (PHP in this case) with information about what to write.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM