September 2002
Intermediate to advanced
544 pages
13h 6m
English
There are several common text-based content types that you might generate with CGI scripts besides HTML. For example, you might want to send images, audio files, or Zip archives to your users via a CGI program. The first step is to set the content type appropriately—the second step is to send the binary content to the user as the body of the request. Sending a text file is simple, here’s a very short script that will do the trick:
#!/usr/local/bin/perl
use CGI;
my $query = new CGI;
print $query->header(-type=>'text/plain');
open (FILE, "< some_file.txt")
or die "Can't open some_file.txt";
while (<FILE>) {
print;
} Sending a binary file to the user is slightly more complex. First, let’s look at a simple script that opens ...
Read now
Unlock full access