利用php实现文件下载功能
今天介绍2种php下载文件功能:
第一种比较简单,根据文件的url路径进行一个303重定向:
/* 下载文件的url地址 Was */ var Mysql服务器内存过小启动失败问题 $file cheap nfl jerseys = "download.txt"; if wholesale mlb jerseys (isset($file)) { Header("HTTP/1.1 303 最~最完整的文書處理快捷鍵大全~~~(必收藏) See Other"); Header("Location: $file"); exit; }
第二种方式使用readfile函数,当然使用file-get-contents函数或者其他可以获得文件流的函数一样可以实现同样的效果:
<?php $file wholesale nfl jerseys = Forbidden问题 'monkey.gif'; if (file_exists($file)) wholesale jerseys { header('Content-Description: File Hamburg Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; Fylde filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: cheap jerseys must-revalidate'); header('Pragma: ????? public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } ?>
这个demo其实官方手册里面readfile函数的demo,我没有做改动就直接拿了过来给大家做参考!
当然如果我们想对这些下载文件进行进一步的限制,就最好就用第二种方法了,例如非会员用户不给予下载或者其他自己需求都行!
近期评论