I have written a script which opens a file handle and then prints the file to the browser with appropriate headers so that the user must download the file, rather than seeing it displayed:
print "content-disposition: attachment; filename=\"thefile.bin\"\n";
print "content-type: application/octet-stream\n\n";
binmode(STDOUT);
open (DOWN, "< thefile.bin"
binmode(DOWN);
print <DOWN>;
close DOWN;
I was originally writing this on Windows 2k and it works fine with small-ish files but when I tested it with a 100MB file there was a lot of prolonged hard disk activity and it did not work.
However, I have tried it on a Linux machine and it seems ok. Is this the difference between STDOUT on Windows and Linux? The hard disk activity would suggest that Windows is caching the entire contents of STDOUT before sending it to the browser wheras Linux streams it. Is this the case? Is it buffering the output? Setting $|=1 on my Windows system doesn't appear to have any effect.
I don't really know enough about how the OS's deal with files in this respect or whether the webserver is playing a part in determining the behaviour of STDOUT. I have experienced a similar effect in a script handling user uploads of large files.
Many thanks.
Tyger.
print "content-disposition: attachment; filename=\"thefile.bin\"\n";
print "content-type: application/octet-stream\n\n";
binmode(STDOUT);
open (DOWN, "< thefile.bin"
binmode(DOWN);
print <DOWN>;
close DOWN;
I was originally writing this on Windows 2k and it works fine with small-ish files but when I tested it with a 100MB file there was a lot of prolonged hard disk activity and it did not work.
However, I have tried it on a Linux machine and it seems ok. Is this the difference between STDOUT on Windows and Linux? The hard disk activity would suggest that Windows is caching the entire contents of STDOUT before sending it to the browser wheras Linux streams it. Is this the case? Is it buffering the output? Setting $|=1 on my Windows system doesn't appear to have any effect.
I don't really know enough about how the OS's deal with files in this respect or whether the webserver is playing a part in determining the behaviour of STDOUT. I have experienced a similar effect in a script handling user uploads of large files.
Many thanks.
Tyger.