This question is trivial and has many answers, all the same or nearly but for my case, it doesn't solve as expected? Goal: send WORD file as attachment with PHP (simple...) Mean: here is the code:
// send the file to the browser
header("Cache-Control: no-store");
header("Content-Type: application/octet-stream");
//header("Content-type: application/msword");
header('Content-Disposition: attachment; filename="'. basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '. filesize($filename));
ob_clean();
flush();
readfile($filename);
exit();
Well, everything seems right but the file I saved on my computer cannot be read by MS-WORD: it reads some special chars like:
PK ! /Œt1« á [Content_Types].xml ...
But if I open the original from the server, everything is ok. I missed something obvious... Any advice is welcome because I tried nearly ALL the methods I read...but still the same result.
call https://stackoverflow.com/download-script.php?file=example.doc
Here it is download-script.php code
From the few characters of content that you show, you're creating an OfficeOpenXML (.docx) file rather than a BIFF (.doc) file, so the content type should be
and the file extension should be .docx
Maybe your uotput file get wrong header. I have something like this in my script, which i use to download files:
Filename I take from db.