Javascript read local text file

2007-09-30 9:47 am
我想寫一個Javascript用黎read一個Seve係Local嘅text file(如:"c:/text.txt")的value呀...
我係會係PHP度Run架, 我之前試過用 黎做, 但讀唔到係local的file, 只係讀倒係server嘅file.
THX....

回答 (2)

2007-09-30 4:39 pm
✔ 最佳答案
The design of the browser prevents the web page from reading the local file. It is for security reasons. Imagine the danger there is when a web page you visit can read your local file. The information from your local file, once read, can be sent to the server easily when you click a link on the web page.
The web page can read file on the server when the account that the server belongs has the permission to read that file. The web page, which is authored by someone unknown to you, can never read a page on your hard drive.
The javascript will get Access denied error.
2007-10-06 10:43 am
還有一個辦法, 就是用 ActiveX object 'FileSystemObject', 不過一定要用 IE, IE 會驚告使用者風險, 使用者同意後先 run 到.

http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx

語法可參考 (只得 VB 的語法, 不過轉成 JS 不難):
http://www.microsoft.com/technet/scriptcenter/guide/sas_scr_iikh.mspx?mfr=true


收錄日期: 2021-04-13 21:01:40
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070930000051KK00479

檢視 Wayback Machine 備份