0

I need to generate a word file every time someone completes a html form. Can someone help me with any piece of code.

YowE3K
  • 23,852
  • 7
  • 26
  • 40
  • 1
    Possible duplicate of [Create and download a text file using php](https://stackoverflow.com/questions/11056033/create-and-download-a-text-file-using-php) – prasanth May 31 '17 at 12:26
  • 2
    I find it extremely difficult to believe you found nothing in a web search about doing this – charlietfl May 31 '17 at 12:31
  • Something [like this](https://www.google.com/#q=Generating+a+word+file+from+a+form+using+php.) perhaps. – alanlittle May 31 '17 at 13:05

2 Answers2

1

You can use HTTP headers

<?php
  header("Content-type: application/vnd.ms-word");
  header("Content-Disposition: attachment;Filename=document_name.doc");    
  echo "<html>";
  echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
  echo "<body>";
  echo "<b>Demo Text</b>";
  echo "</body>";
  echo "</html>";
?>
Rahul
  • 2,374
  • 2
  • 9
  • 17
0

There are tons of libraries for PHP to create Word files.

All you then have to do is adding this to your PHP file:

<?php
    header("Content-type: application/octet-stream");   
?>

This tells the browser that the resource should be downloaded. After that, you just have to output the contents of your generated Word-file.

StuntHacks
  • 457
  • 3
  • 15