内容类型:ms-word下载为.php



Background

我有一个应用程序,它使用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文件…这当然没有预期的功能

尝试不使用循环打印。

    $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'];

相关内容

  • 没有找到相关文章

最新更新