Forum Moderators: coopster

Message Too Old, No Replies

Open, edit and change a word file

         

derek mcgilvray

7:00 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



Hi folks,

I wonder if anyone could tell me whether or not it's possible to open, edit and change a Word document that's accessed online.

I want to open it, make changes then save the changes to the file online, rather than saving as a new file on my pc and re-uploading it.

Any help would be appreciated.

phparion

5:28 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it is very straight forward. use fopen or get_file_content() functions to open the file from its location and display in a <textarea></textarea> , edit it and when submitting form first remove / rename the old file and store the new one.

google php file handling and read the manual of fopen etc functions.

derek mcgilvray

6:47 am on Sep 15, 2007 (gmt 0)

10+ Year Member



Thanks for your comments, phparion, I'd never have thought of using textarea.

However, the textarea displays the source code of the Word doc, rather than the formatted version, even though I've tried this with both .doc and .htm extensions. [What I mean is I can open the file using fopen() and it's displayed just as I'd like, but when displayed within textarea it includes all the code with no formatting]

Any hints as to what I should do?

vincevincevince

7:00 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not easy. You'd need to convert it into HTML first, and then back to word when you're finished. Almost certainly, you will lose a lot of formatting and almost all graphics.

I suggest you work with HTML only and forget about word.

phparion

7:50 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



no need to take this much gamble to convert forward and backwards. use any open source rich text editor i.e WYSIWYG editor to open and edit the file and then save it. I have done such tasks using FCKeditor before.

Sylver

8:31 am on Sep 15, 2007 (gmt 0)

10+ Year Member



The best way I can think of is to use the COM object to interact with Ms Word.

It requires a *server* equiped with Ms Word if you are going to do it with PHP.

You can then use the COM object to get and manipulate the content of a Word Document using Ms Word itself.

Search for it in Google:
[google.com ]

The downside is that first you need Ms Word on the server, and that Ms Word is pretty heavy, memory-wise, so if you have to do a large volume, you better have a dedicated server. You could also try to use OOo filters, but I really know nothing about that.

Another possibility is to extract the content through COM on the client side using javascript and activeX.
<snip>
From there, if you need anything from the server, use Ajax.

The downside is that Ms Word must be installed on the client computer and that ActiveX must be enabled(both factors are outside your control). On the plus side, it saves your server's memory & CPU.

Otherwise, attempting to manipulate directly a typical Word document is ... way out of my league.

[edited by: dreamcatcher at 7:22 pm (utc) on Sep. 15, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]

vincevincevince

9:12 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Google Docs does this well - try using that!

derek mcgilvray

7:09 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Yep, it sounds way out of my league too! I think I'll stick with the download/upload option for now.

Thanks for all the suggestions.

henry0

11:04 am on Sep 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Silver, interesting to read about editing MS world with PHP

But I foresee a security problem
it is almost impossible to regex a word doc
since MS formating contains most of the HTML characters that we would like disallowing
any idea?

Sylver

3:50 pm on Sep 16, 2007 (gmt 0)

10+ Year Member



Silver, interesting to read about editing MS world with PHP
But I foresee a security problem
it is almost impossible to regex a word doc
since MS formating contains most of the HTML characters that we would like disallowing
any idea?

Well, the methods I talk about here collect the text of the Word document, so when it gets to PHP, it's just text and can be parsed & manipulated using regex.

The best way to protect your application depends on what you are doing and what are the dangers you are trying to protect against, but since it's just text (once extracted that is) the usual methods should work.

[edited by: Sylver at 3:55 pm (utc) on Sep. 16, 2007]