문제

Background

I have an application which uses php to print information from a mySQL line, into ms-word... It was working on another part of my website, but after new implementation... my browsers seem to want to download the page as an actual document, rather than give the option to open/save in MS Word... Was wondering if anyone saw an actual problem with the code here... No errors are being displayed in my logs, and full error_reporting is on

Code Excerpt

<?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();
    }
}
?>

As of right now, all that happens when I link to run this php script, it gives me an open/save for the actual PHP file...which of course does not have the intended functionality.

도움이 되었습니까?

해결책

Try to print it without a loop.

    $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'];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top