craete word doc using php script

Discussion in 'PHP' started by ksamir2004, May 6, 2008.

  1. #1
    Hi All,

    i created text editor on web. i want to save all content of editor in word document. can any one help me how to save all content of editor in doc.

    Thanks,
    Sam
     
    ksamir2004, May 6, 2008 IP
  2. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    kreoton, May 6, 2008 IP
  3. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi All,

    can any one help me for creating text editor same as digital forums. it should save in ms word.

    please send code or Advice me on this is highly appreciated.
     
    ksamir2004, May 6, 2008 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    there are premade text editor like here in DP...
    try using TinyMCE
    http://tinymce.moxiecode.com/

    for your question.. how to make a word doc...
    first write it in a php file here's the sample script.

    <?php
    $filename = 'test.txt';
    $somecontent = "Add this to the file\n";

    if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'a')) {
    echo "Cannot open file ($filename)";
    exit;
    }
    if (fwrite($handle, $somecontent) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
    }

    echo "Success, wrote ($somecontent) to file ($filename)";

    fclose($handle);

    } else {
    echo "The file $filename is not writable";
    }
    ?>

    make sure its written, then download the file by a word document format..
    here's the code
    <?php
    header('Content-type: application/msword');
    header('Content-Disposition: attachment; filename="download.doc"');
    readfile('thefilename of the doc');
    ?>
     
    bartolay13, May 7, 2008 IP