Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic creation of a doc/docx document on the users desktop
    primarykey
    data
    text
    <p>My site is HTML/Javascript with AJAX calling server-side PHP. I want to allow the user to click an icon and create a report from MySQL data and then save this on the client's desktop <strong>without</strong> doing a page reload.</p> <p>Options for creating a doc, as I can gather it, appear to be as follows. (I gather it needs to be done server-side, rather than with Javascript.) I'm not sure where the file ends up in each case. Please feel free to correct my misunderstandings :)</p> <p>Method 1 - this appears only to create a .doc file. I'm not sure where the file gets put.</p> <pre><code>$fp = fopen("method1.doc", 'w+'); $str = "&lt;B&gt;This is the text for the word file created through php programming&lt;/B&gt;"; fwrite($fp, $str); fclose($fp); </code></pre> <p>Method 2 - this also appears to create a .doc file.</p> <pre><code>$word = new COM("word.application") or die ("couldnt create an instance of word"); echo "loaded , word version{$word-&gt;version}"; $word-&gt;visible = 1; $word-&gt;Documents-&gt;Add(); $word-&gt;Selection-&gt;TypeText("Sample text."); $word-&gt;Documents[1]-&gt;SaveAs("method2.doc"); $word-&gt;Quit(); $word-&gt;Release(); $word = null; </code></pre> <p>Method 3 - also a .doc file, I think.</p> <pre><code>header('Content-type: application/vnd.ms-word'); header("Content-Disposition: attachment;Filename=method3.doc"); echo "&lt;html&gt;"; echo "&lt;body&gt;"; echo "&lt;b&gt;My first document&lt;/b&gt;"; echo "&lt;/body&gt;"; echo "&lt;/html&gt;"; </code></pre> <p>Method 4 - PHPWord</p> <p>Method 5 - PHPDocx</p> <p>I've tested 1 &amp; 2 in my home dev environment, but I can't find the files! What's the best way forward, please? </p> <p>Thanks :)</p> <p>BTW, I know there are relevant posts <a href="https://stackoverflow.com/questions/7960370/php-dynamically-create-and-download-doc-file">here</a>, <a href="https://stackoverflow.com/questions/3342605/how-to-create-a-msword-doc-file-from-php-that-spans-more-than-one-page-using">here</a> and <a href="https://stackoverflow.com/questions/4153591/generating-word-documents-with-php">here</a>, but none really answers the question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload