ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
"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??
"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??
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
The FileEntry interface of the File System API represents a file in a file system. It lets you write content to a file.
...
This specification is more or less abandoned as it didn't get significant traction among browser makers.
Quote:
Originally Posted by fhleung
The reason I want to WRITE/EDIT a file by Javascript just
because I have NO networking/internet!
This makes no sense, so I wonder if you have some other reason for wanting to write to a file from javascript?
@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)
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.
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.
No networking.
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?
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 technically not possible to do that from a browser and with only DOM scripting. Deal with it. This should have been clear to you if you read and understood what you linked to in your first post, and if you weren't able to understand what you linked to in your first post then you're not ready to do Javascript development by yourself.
A Java applet would be less restricted in terms of filesystem access, but note that I said "less", not "not".
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.