利用PHP对文件进行下载:

  public function download(){
       $file = './public/Uploads/fileuri';   //下载文件存放目录  
       if (file_exists($file)) {
           header('Content-Description: File Transfer');
           header('Content-Type: application/octet-stream');
           header('Content-Disposition: attachment; filename="'.basename($file).'"');
           header('Expires: 0');
           header('Cache-Control: must-revalidate');
           header('Pragma: public');
           header('Content-Length: ' . filesize($file));
           readfile($file);
           exit;
       }else{
           echo "文件不存在";
       }

   }

标签: php

已有 4 条评论

  1. 创业者小峰 创业者小峰

    寥落古行宫,宫花寂寞红。

  2. 周松松博客 周松松博客

    你好,特别邀请您加入博客圈站长交流群

  3. php 下载功能还是不错的了

  4. 实用小程序 感谢分享

添加新评论