php实现文件强制下载
2013-06-02 00:00
253 查看
为什么要实现php文件强制下载呢?一般文件现在用a链接就可以了,现在的浏览器都很牛x啊,什么txt,pdf,excel等待都能实现,直接在浏览器上打开了,如果你不想这么做,那么用php去实现。其实我在之前说php header函数的时候就已经说过了。简单实现原理如下:
读者只要去改良下就行了。
<?php $file_dir = "./"; $name = "test.txt"; $file = fopen($file_dir.$name,"r"); Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length: ".filesize($file_dir . $name)); Header("Content-Disposition: attachment; filename=".$name); echo fread($file, filesize($file_dir.$name)); fclose($file); ?>
读者只要去改良下就行了。
相关文章推荐
- php 强制下载文件实现代码
- PHP 实现文件强制下载
- php简单实现文件或图片强制下载的方法
- php简单实现文件或图片强制下载的方法
- php 强制下载文件实现代码
- 用php把强制下载各类文件的方法
- php实现多文件上传和下载。
- PHP Laravel实现文件下载功能
- php实现批量下载百度云盘文件例子分享
- php实现批量下载百度云盘文件例子分享
- PHP实现文件下载
- 解析PHP实现下载文件的两种方法
- PHP实现文件上传下载——心在忙而已
- IE php关于强制下载文件的代码
- php代码实现文件下载
- php实现的支持断点续传的文件下载类
- php实现文件下载的一段代码
- PHP实现文件下载
- PHP+Mysql+jQuery实现文件下载次数统计