zoukankan      html  css  js  c++  java
  • php实现下载

    PHP实现下载文件的两种方法。分享下,有用到的朋友看看哦。

    方法一:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <?php
    /**
    * 下载文件
    * header函数
    *
    */
    header('Content-Description: File Transfer');
     
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($filepath));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0′);
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0′);
    header('Pragma: public');
    header('Content-Length: ' . filesize($filepath));
    readfile($file_path);
    ?>

    了解php中header函数的用法。

    方法二:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php
    //文件下载
    //readfile
    $fileinfo = pathinfo($filename);
    header('Content-type: application/x-'.$fileinfo['extension']);
    header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
    header('Content-Length: '.filesize($filename));
    readfile($thefile);
    exit();
    ?>

    转自http://www.jb51.net/article/40485.htm

  • 相关阅读:
    [APIO2018] Duathlon 铁人两项
    「PKUWC2018」随机游走
    「2018山东一轮集训」 Tree
    「2018山东一轮集训」Game
    [Lydsy1805月赛] quailty 算法
    CodeForces
    CodeForces
    「2018山东一轮集训」鸽子
    python序列化
    python的shutil模块
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4873873.html
Copyright © 2011-2022 走看看