RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
php下载文件函数
  1. 代码:
    /*
    @desc:php下载文件函数,支持限速
    @param name 待下载文件名
    @param rate 速度,单位kb
    */
    function download($file,$rate=false){
    set_time_limit(0);
    $content = file_get_contents($file);
    $filesize = strlen($content);
    header ('Content-Length: '.$filesize);
    header ('Content-type: application/file');
    header ("Content-Disposition: attachment; filename=".basename($file));
    if($rate){
        ob_start();
        $fr=fopen($file,"rb");
        while (!feof($fr)){
            $data = fread($fr,round($rate*1024));
            echo $data;
            ob_flush();
            flush();
            sleep(1);
        }
        if($fr){
            fclose($fr);
        }
    }else{
        readfile($file);
    }
    }
  2. 测试:
    download('2018.rar',128);
  3. 输出:
    php下载文件函数

当前文章:php下载文件函数
网站网址:http://scyingshan.cn/article/gsidie.html