That simple?

gvim gvimrc at
Tue Apr 24 13:40:50 BST 2012

I'm trying to serve a large zip file (678MB) in 3MB chunks to which I will add password protection. I found the PHP code listed below but wanted to stick with Perl. My first, potentially naive, solution is listed below but I want to make sure I'm not overlooking some essential checking and edge cases.


************ Perl ********************

use CGI::Simple::Standard qw( header );

open my $INFILE, '<', '' or die "Can't open file: $!\n";
print header(-type => 'application/zip', -attachment => '');
while (read $INFILE, my $buffer, 3145728) {
   print $buffer;
close $INFILE;

************** PHP *******************

   function readfile_chunked($filename) {
     $buffer = '';
     $handle = fopen($filename, 'rb');
     if ($handle === false) {
       return false;
     while (!feof($handle)) {
       $buffer = fread($handle, 3145728);
       echo $buffer;
     $status = fclose($handle);
     return $status;

    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename = ""');

More information about the mailing list