PHP将服务器上的文件下载(例如下载Excel模板)
2014-08-05 14:48
302 查看
//下载模板(前提:此文件在服务器上)
public function down()
{
header("Content-type:text/html;charset=utf-8");
$file_name="example.xls";
$file_name=iconv("utf-8","gb2312",$file_name);
$file_sub_path=PC_PATH.'modules/client/';
$file_path=$file_sub_path.$file_name;
if(!file_exists($file_path))
{
echo "没有该文件文件";
return ;
}
$fp=fopen($file_path,"r");
$file_size=filesize($file_path);
//下载文件需要用到的头
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length:".$file_size);
Header("Content-Disposition: attachment; filename=".$file_name);
$buffer=1024;
$file_count=0;
while(!feof($fp) && $file_count<$file_size)
{
$file_con=fread($fp,$buffer);
$file_count+=$buffer;
echo $file_con;
}
fclose($fp);
}
public function down()
{
header("Content-type:text/html;charset=utf-8");
$file_name="example.xls";
$file_name=iconv("utf-8","gb2312",$file_name);
$file_sub_path=PC_PATH.'modules/client/';
$file_path=$file_sub_path.$file_name;
if(!file_exists($file_path))
{
echo "没有该文件文件";
return ;
}
$fp=fopen($file_path,"r");
$file_size=filesize($file_path);
//下载文件需要用到的头
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length:".$file_size);
Header("Content-Disposition: attachment; filename=".$file_name);
$buffer=1024;
$file_count=0;
while(!feof($fp) && $file_count<$file_size)
{
$file_con=fread($fp,$buffer);
$file_count+=$buffer;
echo $file_con;
}
fclose($fp);
}
相关文章推荐
- php excel下载模板方法2,放excel文件在服务器上,直接拉取
- 直接客户端浏览器下载文件,不必通过回传服务器再下载(例如将table内容导出excel)
- php一句话下载文件到服务器
- PHPExcel部署在IIS服务器无法下载问题的处理
- PHP服务器文件管理器开发小结(九):jQuery动态表单实现文件下载
- PHPExcel与ajax结合进行文件下载
- php 下载服务器端的文件 (fsockopen)
- PHP脚本实现服务器文件下载
- php实现从服务器下载文件
- php下载服务器上的文件
- php 压缩服务器上的文件为zip 和下载zip文件
- php实现从ftp服务器上下载文件树到本地电脑的程序
- android从服务器下载文件(php+apache+win7+MySql)
- yii phpexcel自动生成文件保存到服务器上
- 关于服务器上Microsoft Office Excel 不能访问文件 例如Windows服务
- web服务器如何判断客户端文件已下载结束?(php实现)
- PHP—SQL下载为EXCEL文件
- php下载服务器端文件(禁止使用ajax提交请求)
- 在MVC中实现和网站不同服务器的批量文件下载以及NPOI下载数据到Excel的简单学习
- 怎么实现NPOI导出excel保存到服务器上,然后返回文件地址下载?