Quick Search:
 
 PHP Code: Buffered Download code Jump to:  
Category: >> PHP Code >> Buffered Download code  

<< lastnext >>

Snippet Name: Buffered Download code

Description: For downloading very large files (10 meg or more), split the file into chunks when sending.

Comment: (none)

Language: PHP
Highlight Mode: PERL
Last Modified: February 26th, 2009

<?php
 
//start buffered download
    WHILE(!feof($fp)){
 
        $total     = filesize($file);
        $sent      = 0;
        $blocksize = (2 << 20); //2M chunks
        $handle    = fopen($file, "r");
 
        // Now we need to loop through the file 
        // AND echo out chunks of file data
        WHILE($sent < $total){
            echo fread($handle, $blocksize);
            $sent += $blocksize;
        }
 
        EXIT(0);
        @flush();
        @ob_flush();
    }
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org