Jump to content

writing to a text file with javascript


dsaba

Recommended Posts

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

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.