码迷,mamicode.com
首页 > Web开发 > 详细

PHP下载文件的两种方法

时间:2014-07-23 00:32:37      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   使用   

PHP下载文件的两种方法与代码分享

转自:http://www.cnblogs.com/cfinder010/p/3197195.html

PHP实现下载文件的两种方法。分享下,有用到的朋友看看哦。

方法一:

<?php

/**
* 下载文件
* header函数
**/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);?>

以上代码用到了php header函数,可以参考以下如下的文章:
php header()函数的简单例子
php header函数实现文件下载的实例代码
php中header函数的用法举例详解
php header 使用详解
php header函数 文件下载时直接提示保存的代码
php header函数实现文本文件下载的方法
php 文件头部(header)信息详解
php使用header发送各种类型文件下载的例子

了解php中header函数的用法。

方法二:

<?php//文件下载
//readfile$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下载文件的两种方法,布布扣,bubuko.com

PHP下载文件的两种方法

标签:des   style   blog   http   color   使用   

原文地址:http://my.oschina.net/softsky/blog/293911

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!