解析PHP实现下载文件的两种方法

yipeiwu_com4年前PHP代码库
方法一:
复制代码 代码如下:

 header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment; filename='.basename($filepath));
 header('Content-Transfer-Encoding: binary');
 header('Expires: 0′);
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0′);
 header('Pragma: public');
 header('Content-Length: ' . filesize($filepath));
 readfile($file_path);

方法二:
复制代码 代码如下:

 $fileinfo = pathinfo($filename);
 header('Content-type: application/x-'.$fileinfo['extension']);
 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
 header('Content-Length: '.filesize($filename));
 readfile($thefile);
 exit();

相关文章

简单的php 验证图片生成函数

复制代码 代码如下:<?php function yzm($name,$width,$height){ Header("Content-type: image/PNG"); sra...

使用php语句将数据库*.sql文件导入数据库

最简单的php语句把数据库*.sql文件导入数据库 复制代码 代码如下: $sql=file_get_contents("text.sql"); //把SQL语句以字符串读入$sql $...

php5 图片验证码实现代码

GD库的函数 1,imagecreatetruecolor -----创建一个真彩色的图像 imagecreatetruecolor(int x_size,int y_size) //x...

thinkPHP5实现的查询数据库并返回json数据实例

本文实例讲述了thinkPHP5实现的查询数据库并返回json数据。分享给大家供大家参考,具体如下: TP5 实现查询数据库返回json数据(返回json数据函数实例) 返回结果: 复制...

php一些公用函数的集合

/*获得客户端ip地址*/     function getIP() {      &...