1

我正在使用以下代码,在本地使用时它工作得很好,但它可以用于服务器目的吗?

function WriteToFile(data) {
    var currentdate = new Date(); 
    var datetime = "Time: " + currentdate.getDate() + "/" + (currentdate.getMonth()+1)  + "/" + currentdate.getFullYear() + " @ " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var a = fso.OpenTextFile("C:\\logs\\log.txt", 8);
    a.WriteLine(datetime);
    a.WriteLine(data + "\n");
    a.Close();
 }

我已经为我的 Z: 驱动器中的 txt 文件的路径尝试了所有方法,但没有任何运气。这甚至可能吗?我还授予对文件夹“所有人”的访问权限,因此它可以读取和写入,但我仍然无法打开 txt 文件进行编辑。作为记录,我使用的是 IE8。

有什么建议么?

4

1 回答 1

1

You cannot access any of the files on the server with the ActiveX Scripting.FileSystemObject using the syntax in your example. This is since the ActiveX FileSystemObject control will be executed on the client side because there's no remote server specified and therefore it only has access to the client's file system. You could specify a remote server using your syntax, but it's not supported in IE 9 standards mode, or IE 10 and above, so it's not really recommended.

Instead, to access the server's file system you will need to create a FileSystemObject on the server side using a server-side language such as Active Server Pages (ASP). In ASP FileSystemObject it would be instantiated using Server.CreateObject("Scripting.FileSystemObject")

Some good examples for using FileSystemObject with ASP can be found here: http://support.microsoft.com/kb/218606 and here:http://www.codeproject.com/Articles/7296/Reading-Files-in-ASP-and-How-to-Search-for-a-parti

于 2013-04-13T16:21:34.067 回答