0

背景

我有一个应用程序,它使用 php 将信息从 mySQL 行打印到 ms-word... 它正在我网站的另一部分工作,但在新实施之后... my browsers seem to want to download the page as an actual document,而不是提供打开/保存MS Word ...想知道是否有人在这里看到代码的实际问题... No errors are being displayed in my logs, and full error_reporting is on

代码摘录

<?php
$id= "1";
$type= "failValidate";

if ($type=="failValidate"){

    $query_letters = "SELECT * FROM table WHERE id=$id";
    try {
        $letters = $customer->runQuery($query_letters);
        header("Content-type: application/vnd.ms-word");
        foreach($letters as $letter) {
            $filename = "letter.doc";
            header("Content-Disposition: attachment;Filename=" . $filename);
            echo $letters[0]['letter'];
        }   
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }
}
?>

截至目前,当我链接运行这个 php 脚本时发生的所有事情,它为我提供了一个打开/保存实际 PHP 文件的功能……当然,它没有预期的功能。

4

1 回答 1

1

尝试在没有循环的情况下打印它。

    $letters = $customer->runQuery($query_letters);
    $filename = "letter.doc";
    header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment; filename=" . $filename);
    echo $letters[0]['letter'];
于 2013-05-05T22:08:39.320 回答