CoderZone.org

Category: >> PHP Code >> Buffered Download Code Bookmark and Share

<< lastnext >>

Snippet Name: Buffered Download Code

Description: Useful for allowing the download of large files (10 meg or more). This splits the file into smaller pieces and reduces the overall load on the server.

Comment: (none)

Author: CoderZone
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();
    }
 
?>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 11