user1445117
user1445117

Reputation: 199

Open an editor locally using the web browser and retrieve the data on the server using php?

I am struggling for days to solve this problem and it seems i cant find any good helpful guidance. So the problem is i want to implement a feature in my web application to give the users the option of editing a text on any editor they have locally and then save the file (the saved file will be online).

Suggested Solution: well my idea is:

1)to create a folder for the user locally on the browser file location.

2)open the applications using exec() (before doing so checking what kind of operating system the user use and create the appropriate error handling)

3)save the file will should be in the created file(point 1).

4)Retrieve the data from the folder.

Please advice me if u have a better idea?

Upvotes: 2

Views: 148

Answers (2)

GordonM
GordonM

Reputation: 31750

What you're trying to do is impossible. PHP is server-side and it has no control over the client, it can only send it a sequence of characters to render (the page that gets displayed).

There are javascript-based rich editors such as CKEditor and TinyMCE which you can provide for the client to use, but that's about as far as you can go. Additionally, as every web browser is a little different from the other and has its own quirks and bugs when it comes to running client side javascript/DOM operations, you can expect a lot of weird little issues that happen in one particular version of one particular browser but not in others. And if the client has javascript turned off they won't see any editor at all.

Upvotes: 3

LSerni
LSerni

Reputation: 57418

In short, you can't do all that. You can do some of that. Remember, with HTTP the user is in complete control, and you can do nothing "on the user's machine". If you could, that would be called "a dangerous security exploit" and would stop working as soon as the various browsers' coders got to it.

You can send the output to the user with an appropriate MIME type, that will open the editor of your choice. You can even invent your own MIME type to do that (the user must install the editor by himself).

Then the user will save the text on his machine. You can't save on a remote machine (not in all editors), since it is not a "save", it is an "upload" that you want.

Finally the user can recover the file he or she just saved, and submit it to you via a POST form, for example.

Frankly, where I live we call this "how to put one's ass before other people's kicks". Just think of all the possible editors, each maybe with its own format: if the user (un)knowingly chooses something weird such as "Save in Word 2015 Extra Format (Compressed)", and uploads the file to your server -- are you prepared to understand the file format and do something meaningful with it?

A very common alternative is to implement any one of several Rich Text Editors in HTML - there's CKEdit, for example, or TinyMCE, and so on. They will let the user produce clean HTML and upload it on your server automatically.

Upvotes: 2

Related Questions