Can we save ckeditor data into doc file

in my site the admin edits some data which i need to save to a doc file. so i implemented this using ckeditor. It works fine but when i try to open this file it says “word cannot start the converter mswrd632.wpc”. what am i doing wrong?

$content=addslashes(trim($_REQUEST['CKEditor']))
$docfile="convert.doc";
$fp = fopen("files/".$docfile, "w+");
fwrite($fp, $content);                                                           

this is my code
how can we save data to a doc file.is there any other way?

<p class="body">
    England would be keen to finish the summer on a high note by also remaining unbeaten in the upcoming ODI series against world champions India, said Test skipper Andrew Strauss after handing out the visitors a 4-0 whitewash.</p>

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

There is no problem with your code. The problem is that the file you are creating is a regular text file with the doc extension, in other words not a real Word file. If you don’t have to write a doc file, just keep it as a plain .txt and that will solve the problem.

Now if your project specs require you to have that file as a doc, you can do the following:

  1. Use the “HTML” approach(no COM required)
    Take a look at Sergey Kornilov’s post: Create Word Document using PHP in Linux

    There is also a similar question here: Reading/Writing a MS Word file in PHP

  2. Use a COM Object – you will have to go that route if you need an elaborate word file

This is from my experience. Let’s hope somebody will come up with a better and more efficient solution.

Good Luck!

UPDATE:
I automatically assumed you are working in a Win environment. In this case COM will do, if you need it to work on a Linux machine, your alternative is OpenOffice

This is a decent article on COM and stuff: http://www.webcheatsheet.com/php/create_word_excel_csv_files_with_php.php#wordcom

For OpenOffice just look at their API – http://api.openoffice.org/
Take a look at their forum, I am sure they have examples with PHP.

My personal advice is to play with those, but work on a final solution after a day or two, if you have the time. Writing Word files is certainly not my forte, so there could possibly be another way of handling this.

Good luck!

UPDATE

<html>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<body>
<p>England would be keen to finish the summer on a high note by also remaining unbeaten in the upcoming ODI series against world champions India, said Test skipper Andrew Strauss after handing out the visitors a 4-0 whitewash.</p>
</body>
</html>

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply