I can download my microsoft word successfully if I named it in the filename by default. But if I use $variables to name it. The document extension will be unknown.
Sample:
$No = 1;
$Name = 'John';
$Test = 'Science';
//Download header
$document->save($doc);
header('Content-Description: File Transfer');
header('Content-Type: application/msword');
header("Content-Disposition: attachment; filename='$No_$Name_$Test.docx");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($doc));
ob_clean();
flush();
readfile($doc);
So if i rename my filename as variables. The file download will be without the docx extension. Anyone can advise?
Thanks
One way to copy headers and footers from a worksheet in one workbook to a worksheet in another is to use the traditional editing methods of copying and pasting. In other words, you can select the header material you want to copy, press Ctrl+C, display the header in the target worksheet, and then press Ctrl+V.
Correct headers are
for Excel (*.xlsx):
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $fileName . '"');
for Word (*.docx):
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment;filename="' . $fileName . '"');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With