PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    php 文件下载代码

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:文件下载是项目中经常使用到,今天分享一个小案例给大家,希望对大家有所帮助

    1. <?php 
    2.  
    3. $filename = $_GET['filename']; 
    4.  
    5. // 修改这一行设置你的文件下载目录 
    6. $download_path = "ficheros/"
    7.  
    8. // 不能下载上一层目录的文件 
    9. if(eregi("\.\."$filename)) die("抱歉,你不能下载该文件!"); 
    10. $file = str_replace(".."""$filename); 
    11.  
    12. // 包含 .ht 的文件不能下载 
    13. if(eregi("\.ht.+"$filename)) die("抱歉,你不能下载该文件!"); 
    14.  
    15. // 创建文件下载路径 
    16. $file = "$download_path$file"
    17.  
    18. // 判断文件是否存在 
    19. if(!file_exists($file)) die("抱歉,文件不存在!"); 
    20.  
    21. //  文件类型,作为头部发送给浏览器 
    22. $type = filetype($file); 
    23.  
    24. // 获取时间和日期 
    25. $today = date("F j, Y, g:i a"); 
    26. $time = time(); 
    27.  
    28. // 发送文件头部www.bcty365.com 
    29. header("Content-type: $type"); 
    30. header("Content-Disposition: attachment;filename=$filename"); 
    31. header("Content-Transfer-Encoding: binary"); 
    32. header('Pragma: no-cache'); 
    33. header('Expires: 0'); 
    34. // 发送文件内容 
    35. set_time_limit(0); 
    36. readfile($file); 
    37.  
    38. ?> 

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-2984-1.html
    相关热词搜索: