PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

PHP 弹出文件下载 原理 代码_PHP教程

原创
2016-07-13 10:19:50 731浏览

PHP 弹出文件下载 原理 代码

/**
 * @author      default7
 * @description 演示PHP弹出下载的原理
 *
 * @param $file_name
 */
function downFile($file_name)
{
    $file_path = "/tmp/" . $file_name;
    $buffer = 102400; //一次返回102400个字节
    if (!file_exists($file_path)) {
        echo "";

        return;
    }
    $fp = fopen($file_path, "r");
    $file_size = filesize($file_path);
    $file_data = '';
    while (!feof($fp)) {
        $file_data .= fread($fp, $buffer);
    }
    fclose($fp);

    //Begin writing headers
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-type:application/octet-stream;");
    header("Accept-Ranges:bytes");
    header("Accept-Length:{$file_size}");
    header("Content-Disposition:attachment; filename={$file_name}");
    header("Content-Transfer-Encoding: binary");
    echo $file_data;
}


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/871201.htmlTechArticlePHP 弹出文件下载 原理 代码 /** * @author default7 * @description 演示PHP弹出下载的原理 * * @param $file_name */function downFile($file_name){ $file_path = "/tmp/...
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。