home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- # Access the environment variable by name
-
- $http_accept = $ENV{'HTTP_ACCEPT'};
-
- # Unbuffer output so that we can see the image as it comes out,
- # rather than waiting for the buffer to flush.
-
- $| = 1;
-
- # Test the value and take the appropriate action. For the first test,
- # check whether the browser accepts JPEG images where the "image/jpeg"
- # string will be found in the HTTP_ACCEPT list and if so then send a
- # JPEG image to the browser.
-
- if ($http_accept =~ m#image/jpeg#)
- {
- # Browser understands JPEGs so send it a JPEG image
- &DumpFile("lighthou.jpg", "image/jpeg");
- }
-
- # Check whether the browser accepts GIF images. If the string "image/gif" is
- # found in the HTTP_ACCEPT list then the browser claims to support GIF images
- # so send it one.
-
- elsif ($http_accept =~ m#image/gif#)
- {
- # Browser understands GIFs so send it a GIF image
- &DumpFile("lighthou.gif", "image/gif");
- }
-
- # If the HTTP_ACCEPT value is not defined or neither image types (JPEG or GIF)
- # are supported then it will fail the first two tests. For this case perform
- # the default action which is to show some text.
-
- else
- {
- # Browser does not understand GIFs nor JPEGs so show some plain old text
- print "Content-type: text/plain\n\n";
- print "Text is the only thing I can show you.\n";
- print "Hope you weren't expecting an image or something.\n";
- }
-
- # Exit the program
-
- exit;
-
- sub DumpFile
- {
- local($filename, $content_type) = @_;
-
- # Open the specified file
-
- unless (open(FILE, "$filename"))
- {
- print "Content-type: text/plain\n\n";
- print "Sorry, the file '$filename' cannot be opened.\n";
- print "Please report this error to the webmaster.\n";
- exit;
- }
-
- # Identify what type of file will be sent to the browser with the
- # MIME type from which the variable $content_type will either be
- # "image/jpeg "or "image/gif" depending on what the browser supports.
-
- print "Content-type: $content_type\n\n";
-
- # Read and print out the entire file.
-
- while (<FILE>)
- {
- print;
- }
-
- # Close the file and return to the main program.
-
- close(FILE);
- }
-
- #
- # end of chk-acpt.pl
- #
-