[SOLVED] docx-download within a form application

Hello,

I try to download a file (*.docx) which was generated with PHPWord and stored in a folder of the application server. The following code

header(‘Content-Type: application/octet-stream’);
header(‘Content-Length:’ .filesize($filename));
header(‘Content-Disposition: attachment; filename=’ .basename($filename));
header(‘Content-Transfer-Encoding: binary’);
readfile($filename);

appends the file to the HTML-code of the form application. The result is worthless but it cannot be read with any host-application (Word, OpenOffice etc.).

Is there anybody who can help me?

Hans

I found the reason by myself. Here is the working code:

$download_file = “/path_to_download/filename.docx”;
header(“Pragma: public”);
header(“Content-type: application/docx”);
header(“Content-Transfer-Encoding: binary”);
header(“Content-Disposition: attachment; filename=”".basename($download_file)."";" );
header("Content-Length: ".filesize($download_file));
ob_clean();
flush();
readfile($download_file);