how to JavaScript WRITE file but not read file
Dear all,
I would like to WRITE/EDIT a file by Javascript As far as I know, it could be done by Javascript + php + some XML If I ONLY use php to parse the file and then WRITE it by server side, what is the difference from above? like pros and cons? The reason I want to WRITE/EDIT a file by Javascript just because I have NO networking/internet! so I want to use browser to open the file and then WRITE/EDIT. https://developer.mozilla.org/en-US/.../API/FileEntry |
Using Javascript to write to a file is not the easiest solution. Allowing a language to write to the filesystem via the browser is considered to be a security risk and so Javascript, the language, doesn't permit this. It is possible to get Javascript to write to a file which can be downloaded but I would suggest that alternative languages would be much better suited to your requirements.
|
> The reason I want to WRITE/EDIT a file by Javascript just because I have NO networking/internet!
You mean you want to edit local files with Apache+PHP+own_PHP_program+browser+own_JS_program? notepad.exe would be a better solution. |
The HTML5 filesystem API is extremely limited for obvious security reasons. You can't just store files anywhere you want, for example.
|
"notepad.exe would be a better solution."
I know notepad.exe can edit the file I need, I can also open the file by browser like: File -> Open Ctrl+O -> browse Now most web applications have 3 parts which is APACHE web server + PHP script language + XX SQL database (date file) SQL database/data file can be read/write through the web browser interface, it seems sort of secure... That's the way they doing, I mean the data file NOT read/write directly by notepad.exe but indirectly by web browser "Allowing a language to write to the filesystem via the browser is considered to be a security risk" I can open the core data file/databaseIf open and write the filesystem/file directly... that means I can open the core data file/database directly, I'd think it better using browser to write |
"It is possible to get Javascript to write to a file which can be downloaded but I would suggest that alternative languages would be much better suited to your requirements."
So again, do you mean Javascript CAN write to a file?? |
Quote:
From the page linked in the original post, please read...: Quote:
Quote:
|
@OP: Do you realize that JavaScrcipt and PHP are entirely different things?
1. PHP runs on the server; JavaScript, on the client. 2. PHP is able to use both databases and files; JavaScript is unable (or with serious restrictions) |
Yes, PHP is server side script language and Javascript need only browser to run.
No, Javascript cannot connect to XX SQL database, but javascript can read other file type. |
Javascript can be used to write to a temporary file which you can then "download". These files don't get written to the file system and so they don't get "saved" in the normal sense. This is for security reasons, if the language allowed you to write to the users filesystem then writing viruses in Javascript would be easier and the virus payload could become more destructive.
Your description of a web application is not complete. You need to consider where the various parts are. Crudely, the database and scripting language are on the server whilst the browser and Javascript are on the user's computer. So it is fine to get the scripting language, or even the Javascript to ask questions of the database because the database is on the server and that is the purpose of the database, whilst the user would be surprise if after viewing a web site the files on their computer had changed. |
But to point out one more time...
Quote:
No internet. So it can only be for use on the client machine where the javascript is running. So whether or not there is a server running on that machine, it makes no sense at all to try to write a file from javascript - the user ALREADY HAS ACCESS and can use a text editor - unless the OP has left out some important aspect of the intended use. So please bear with me as I ask once more - what is the actual reason that you want to write from javascript? |
Quote:
A Java applet would be less restricted in terms of filesystem access, but note that I said "less", not "not". |
I heard a javascript related thing: NODEJS
you think that would work/answer? |
Quote:
http://appjs.com/ https://github.com/rogerwang/node-webkit http://spring.io/blog/2012/10/11/scr...r-from-vmware/ The way it works is that the user has to start up a nodejs server on his or her local machine, and then the browser interacts with that local server that's running in the background. |
All times are GMT -5. The time now is 09:03 AM. |