javascript - Writiing to a SERVER file using JS -
tried solutions.. none of them seem work me.
basically, have website uploaded on server has button when clicked simple task of loading file server, displaying , adding +1 , saving back.
the main question arises, tried ways find on net save file doesn't seem work me. specific advice on how can fix issue using js?
update - 1 way using - (doesn't work tho)
fso = new activexobject("scripting.filesystemobject"); var s = fso.createtextfile("total.txt", true); var text = test1; s.writeline(text); s.close();
where test1 name of variable trying write.
assuming have php on server try js
var data = new formdata(); data.append("data" , 1); var xhr = (window.xmlhttprequest) ? new xmlhttprequest() : new activexobject("microsoft.xmlhttp"); xhr.open( 'post', '/path/to/php', true ); xhr.send(data);
php script
<?php if(!empty($_post['data'])){ $data = $_post['data']; $fname = "filname.txt" $file = fopen("upload_or_whatever_path/" .$fname, 'w') or die("unable open file!");// open file fwrite($file, $data); fclose($file); } ?>
Comments
Post a Comment