php生成txt.word.xls直接下载代码
2011-05-09 09:15
411 查看
php如何利用header函数实现点击特殊文件连接后提示下载保存解决方案
相信很多人在实现文件下载功能时会遇到这种情况,本意是点击下载连接提示保存对话框,事情往往事与愿违,例如TXT、图像文件JPG、GIF、PDF等这样的文件会直接在浏览器中打开文件内容,而不是提示保存。通过下面的方法可以解决这个问题。
<?php
if (sExport == "txt" ){女装品牌排行榜
header("Content-Type: application/force-download");//关键之一,提示下载(如:header("Content-Type:text/html");可能直接打开?)
header("Content-Disposition: attachment; filename=".$TxtName);//实际的文件名
//include_once("XXX.php"); //php代码(你把原来的php复制一份,去掉输出html标签)。
}
?>
//如果是xsl,word等则更简单,只需直接在原来的php文件开头加上下面几句:
//(因为word能直接编辑html标签)
<?php
if(sExport == "excel"){
header("ContentType = application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$oTitle.".xls");
}
if(sExport == "word"){
echo
("<div align='center'><font
size=+2>收文登记簿</font><hr size=3 align='center'
width=360></div><br>");
header("ContentType = application/vnd.ms-word");//或试试 application/msword
header("Content-Disposition: attachment; filename=".$oTitle.".doc");
}
if( sExport == "csv"){
header("ContentType = application/csv"); //图像image/jpeg",或image/*"
header("Content-Disposition: attachment; filename=".$oTitle.".csv");
}
//.....输出原来的php代码
?>
相信很多人在实现文件下载功能时会遇到这种情况,本意是点击下载连接提示保存对话框,事情往往事与愿违,例如TXT、图像文件JPG、GIF、PDF等这样的文件会直接在浏览器中打开文件内容,而不是提示保存。通过下面的方法可以解决这个问题。
<?php
if (sExport == "txt" ){女装品牌排行榜
header("Content-Type: application/force-download");//关键之一,提示下载(如:header("Content-Type:text/html");可能直接打开?)
header("Content-Disposition: attachment; filename=".$TxtName);//实际的文件名
//include_once("XXX.php"); //php代码(你把原来的php复制一份,去掉输出html标签)。
}
?>
//如果是xsl,word等则更简单,只需直接在原来的php文件开头加上下面几句:
//(因为word能直接编辑html标签)
<?php
if(sExport == "excel"){
header("ContentType = application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$oTitle.".xls");
}
if(sExport == "word"){
echo
("<div align='center'><font
size=+2>收文登记簿</font><hr size=3 align='center'
width=360></div><br>");
header("ContentType = application/vnd.ms-word");//或试试 application/msword
header("Content-Disposition: attachment; filename=".$oTitle.".doc");
}
if( sExport == "csv"){
header("ContentType = application/csv"); //图像image/jpeg",或image/*"
header("Content-Disposition: attachment; filename=".$oTitle.".csv");
}
//.....输出原来的php代码
?>
相关文章推荐
- php直接生成txt下载
- php代码生成txt文件并下载
- php在程序中将网页生成word文档并提供下载的代码
- php 生成word文档并下载代码
- php在程序中将网页生成word文档并提供下载的代码
- 直接用php创建word文档代码(系统无需安装word软件)
- PHP在线生成txt文件下载
- PHP实现txt文件生成与下载
- 使用VS.NET生成word文档并直接下载
- php 在客户端生成txt文件并且下载
- php生成txt文件实例代码介绍
- 使用VS.NET生成word文档并直接下载
- PHP生成一张含有二维码的图片(文章末尾附代码下载链接)
- java直接生成zip压缩文件精简代码(跳过txt文件)
- 由PHP代码直接生成UML图
- PHP代码为什么不能直接保存HTML文件——>PHP生成静态页面教程
- php生成word,并下载
- 文件直接下载 (PHP代码函数)
- 使用Asp.Net生成Word文档并直接下载
- txt,doc,xls等文本类型的文件,怎样才能直接下载