php 下载

<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/6/11
 * Time: 10:52
 */
class downFile
{
    private $filename;

    function __construct($filename)
    {
        $this->filename = $filename;

    }

    function down()
    {
        $this->filename = iconv('utf-8', 'gb2312', $this->filename);
        //文件名

        $this->filename=str_replace('\\','/', $this->filename);
        $name = explode('/', $this->filename);
        $end1 = end($name);
        //文件类型
        $type = explode('.', $end1);
        $end = end($type);

        if (file_exists($this->filename)) {
            //        header("Cache-control: max-age=".$expire);
            //header('Cache-Control: no-store, no-cache, must-revalidate');
//        header("Expires: " . gmdate("D, d M Y H:i:s",time()+$expire) . "GMT");
            header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . "GMT");
            header("Content-Disposition: attachment; filename=" . $end1);
            header("Content-Length: " . filesize($this->filename));
            header("Content-type: " . '.' . $end);
            header('Content-Encoding: none');
            header("Content-Transfer-Encoding: binary");
//**********************************
            ob_clean();
            flush();
//*********************************
            readfile($this->filename);
        } else {
            echo '<script>alert("未找到文件");
                    location.href="'.SITE_URL.'";
                    </script>';


        }
    }
}

您可以选择一种方式赞助本站

支付宝转账赞助

支付宝扫一扫赞助

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

图片 表情