Yes, this would take a lot of memory if you read in a large file to a string first.
To force download of a large file, just print the file as you read it in like this:
if(-e $file) {
if(open(SESAME, "< $file")) {
print "Content-Disposition: attachment; filename=$file\n";
print "Content-Type: application/octet-stream\n";
print "Content-Length: " . (-s $file) . "\n\n";
while(<SESAME>) {
print $_;
}
close(SESAME);
}
else {
print "Content-Type: text/html\n\nError: Could not read from f
+ile\n";
}
}
else {
print "Content-Type: text/html\n\nError: invalid filename\n";
}
|