zoukankan      html  css  js  c++  java
  • PHP做下载文件的方法

    <?php
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=ins.jpg"); 
    readfile("imgs/test_Zoom.jpg");
    ?>
    

    第一行代码是强制下载;

    第二行代码是给下载的内容指定一个名字;

    第三行代码是把下载的内容读进文件中。

    Example #1 Forcing a download using readfile()

    <?php
    $file = 'monkey.gif';
    
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        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($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    ?>
    

    http://www.php.net/manual/en/function.readfile.php

  • 相关阅读:
    JavaScript中的数组
    JavaScript中的对象
    Highcharts中设置x轴为时间的写法
    CSS 选择器(基础)
    DOM节点
    平衡木蜻蜓
    python2.7 qt4
    C语言优先级
    树莓派与stm32通信
    linux下USB转串口配置
  • 原文地址:https://www.cnblogs.com/jiji262/p/2756527.html
Copyright © 2011-2022 走看看