PHP 下载文件到浏览器
2017-12-14 22:10
204 查看
方法一
a标签H5属性download属性,<a download='test.txt' href='http://www.baidu.com'>下载test.txt文件</a>
方法二
PHP直接输出
ob_start();
$filename=$_GPC['url'];
$title=substr($filename,strrpos($filename,'/')+1);
$size=readfile($filename);
//var_dump($size);exit;
Header( "Content-type:application/octet-stream");
Header( "Accept-Ranges:bytes");
Header( "Accept-Length:");
header( "Content-Disposition: attachment; filename= $title");
//echo file_get_contents($size);
exit;
方法三
$filename=$_GPC['url'];
$title=substr($filename,strrpos($filename,'/')+1);
$file = fopen($filename, "rb");
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
Header( "Content-Disposition: attachment; filename= $title");
$contents = "";
while (!feof($file)) {
$contents .= fread($file, 8192);
}
echo $contents;
fclose($file);
a标签H5属性download属性,<a download='test.txt' href='http://www.baidu.com'>下载test.txt文件</a>
方法二
PHP直接输出
ob_start();
$filename=$_GPC['url'];
$title=substr($filename,strrpos($filename,'/')+1);
$size=readfile($filename);
//var_dump($size);exit;
Header( "Content-type:application/octet-stream");
Header( "Accept-Ranges:bytes");
Header( "Accept-Length:");
header( "Content-Disposition: attachment; filename= $title");
//echo file_get_contents($size);
exit;
方法三
$filename=$_GPC['url'];
$title=substr($filename,strrpos($filename,'/')+1);
$file = fopen($filename, "rb");
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
Header( "Content-Disposition: attachment; filename= $title");
$contents = "";
while (!feof($file)) {
$contents .= fread($file, 8192);
}
echo $contents;
fclose($file);
相关文章推荐
- php -- PHP实现点击a标签的href做链接时,直接保存文件(任何类型),而不是通过浏览器直接打开下载的文件
- PHP 生成.csv 文件并下载到浏览器
- PHP下载txt文件到浏览器
- 浏览器访问服务器上.php文件不解析直接下载
- php中强制浏览器下载文件
- php强制文件下载而非在浏览器打开的自定义函数分享
- [置顶] PHP解决浏览器 下载文件 中文名称乱码问题--兼容大多浏览器
- php导出csv数据在浏览器中输出提供下载或保存到文件的示例
- PHP强制浏览器不打开而是下载文件
- 兼容ie6浏览器的php下载文件代码分享
- 兼容ie6浏览器的php下载文件代码分享
- 浏览器通过apache访问php文件提示下载问题,更改项目文件目录
- PHP解决浏览器 下载文件 中文名称乱码问题--兼容大多浏览器
- php强制文件下载而非在浏览器打开的自定义函数分享
- php强制文件下载(避免文件或图片直接在浏览器中打开)
- Ubuntu下apache2无法解析php文件,浏览器提示下载所要打开的php文件
- php导出csv数据在浏览器中输出提供下载或保存到文件的示例
- php 文件下载的相关代码 兼容所有浏览器
- php大力力 [029节] 做PHP项目如何下载js文件:使用腾讯浏览器把网上案例页面存储到本地
- PHP 生成.csv 文件并下载到浏览器