dsaba Posted June 19, 2007 Share Posted June 19, 2007 Hello I'm having trouble writing to a text file with javascript, i've tried writing to a local text file on my own PC, and I've also tried writing to a local file on my own server, (which I have all permissions to do so...) I'd really like to write to a file that resides on my own web server. Here is my code: <head> <SCRIPT LANGUAGE="JavaScript"> function WriteToFile() { set fso = CreateObject("Scripting.FileSystemObject"); set s = fso.CreateTextFile("C:\test.txt", True); s.writeline("HI"); s.writeline("Bye"); s.writeline("-----------------------------"); s.Close(); } </SCRIPT> </head> <body> <form onSubmit="WriteToFile()"> <input type="submit" value="Run the WriteToFile Function!"> </form> </body> quite frankly it just doesn't work, you know what I want to do, I gave you my attempt, please help me do it thank you Quote Link to comment Share on other sites More sharing options...
nogray Posted June 19, 2007 Share Posted June 19, 2007 The filesystemobject is only an IE object and only works on .hta (HTML application) file. You can't write to the server using JavaScript because it's a huge security issue (anyone can hack your site by writing server side files). User a server side script to write the file such as PHP or ASP, Quote Link to comment Share on other sites More sharing options...
dsaba Posted June 19, 2007 Author Share Posted June 19, 2007 ah that sucks, I am well familiar how to write to a file using PHP however I was reallying needing to do it with javascript on a security issue I can sort of see how it is a problem, but still if I have set permissions to write to my own server files on my own server, that means no visitor or outside script can write to my server, why should it be a security issue? if someone hasn't setup their own permissions correctly and allowed a visitor to write to their files, then this same "security" issue could be done with an external php script I'll be content using javascript to write to my own local files on my own PC, but my method above didn't work, perhaps you know another way and can show me some code? Quote Link to comment Share on other sites More sharing options...
nogray Posted June 20, 2007 Share Posted June 20, 2007 If you running the script from your own pc, make it an HTA file (HTML application) more on hta http://msdn2.microsoft.com/en-us/library/ms536496.aspx This will give you the security clearness to write to your own pc (if you have Norton antivirous, you'll get a warrning). If it's live, than you can't write using front end script, you can use JScript.net, but thats works on the server side as well. The issue is if someone gained access to your page that write the files, they can add a script to the URL query to comprimize your site. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.