尝试将数据从表单发送到word文档作为下载?

时间:2013-12-17 02:18:01

标签: php forms ms-word

我是一个菜鸟,所以如果这是完全错误我道歉但我感谢你们提前帮助。我试图从我的表单中获取数据输入以自动插入到可以下载的word文档中。

这是我的表单代码:

<form class="firstresume.php" method="post">
<input  value="Name *"  name="Your_Name" class="autoclear name-newsletter"     >
<input  value="Email *"  name="Your_Email"  class="email-newsletter"     >
<input  value="Phone *"  name="Your_Phone"  class="phone-newsletter"   >
<input type="submit" value="Submit" name="subscribe"  class="button-newsletter">
</form>

这是我的firstresume.php代码:

<?php 


    // opens the file you created
$hlines = file("resume.htm");
// creates a new word document
$handle = fopen("C://NewResumé.doc","w+");
// here you replace all the keywords with user's information
foreach($hlines as $hline_num => $hline)
{
    $hline = str_replace("Your_Name",$_REQUEST["Your_Name"],$hline);
        $hline = str_replace("Your_Phone",$_REQUEST["Your_Phone"],$hline);
        $hline = str_replace("Your_Email",$_REQUEST["Your_Email"],$hline);
        fwrite($handle,$hline."\n");
}
?> 

2 个答案:

答案 0 :(得分:0)

您可以尝试 firstresume.php 文件,例如:

<?php
  header("Content-type: application/vnd.ms-word");
  header("Content-Disposition: attachment;Filename=resume.doc");    
  echo "<html>";
  echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
  echo "<body>";
  echo "<p>Your Mail: $_REQUEST['Your_Name']</p>";
  echo "<p>Your Phone: $_REQUEST['Your_Phone']</p>";
  echo "<p>Your Email: $_REQUEST['Your_Email']</p>";
  echo "</body>";
  echo "</html>";
?>

答案 1 :(得分:0)

查看PHPWord项目。这些人有一个PHP库,可以修改(简单)模板并输出新的docx文件。

在最新版本中,有两个文件(Template.php和Template.docx)似乎完全具有代码和&amp;您正在寻找的功能!