Announcement

Collapse
No announcement yet.

[SOLVED] docx-download within a form application

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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

  • #2
    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);
    Last edited by herrhans; 12-03-2012, 04:59 PM.

    Comment

    Working...
    X