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

//start buffered download
        $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;
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 7