merlin

精益求精

孤鸿

导航

读取大文件 php

        ob_end_clean();
        set_time_limit(0);
        ob_start();
        $filename = basename($path);
        $suffix = self::extension($filename);
        
        header('Content-Type:'类型' );
        header('Content-Disposition: attachment; filename=' . $filename);
        
        //读取超大文件
        $handle = fopen($path,'rb');
        if( $handle )
        {
            flock($handle,LOCK_SH);
            while(!feof($handle)){
                $buffer = fread($handle,1024*1024);
                echo $buffer;
                ob_flush();
                flush();
            }
            flock($handle,LOCK_UN);
            fclose($handle);
        }

 

posted on 2013-11-18 17:52  天地一连线_孤鸿挂飘渺  阅读(165)  评论(0编辑  收藏  举报