http标题用于下载Microsoft Word和Excel文件 [英] http header for downloading Microsoft Word and Excel files
本文介绍了http标题用于下载Microsoft Word和Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我默认将其命名为文件名,我可以成功下载我的微软单词。但是,如果我使用$变量来命名它。
样品:
$无= 1;
$ Name ='John';
$ Test ='Science';
//下载标题
$文件 - >保存($ 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);
所以,如果我将我的文件名重命名为变量。文件下载将没有docx扩展名。任何人都可以建议?
谢谢
更改此 header('Content-Type:application / msword');
至
header('Content-Type:application / octet-stream');
编辑:
p>
header(Content-Disposition:attachment; filename ='$ No_ $ Name_ $ Test.docx);
至
header(Content-Disposition:attachment; filename = \{$ No} _ {$ Name} _ {$ Test} .docx \);
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
解决方案
Change this
header('Content-Type: application/msword');
to
header('Content-Type: application/octet-stream');
EDIT:
And change
header("Content-Disposition: attachment; filename='$No_$Name_$Test.docx");
to
header("Content-Disposition: attachment; filename=\"{$No}_{$Name}_{$Test}.docx\"");
这篇关于http标题用于下载Microsoft Word和Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文