#!/usr/bin/perl -w use strict; use warnings; use CGI::Carp qw{ fatalsToBrowser }; use IO::File; my $png = "test.png"; my $fh = new IO::File($png) or die "Can't read file '$png' ($!)\n"; my $nbytes = (-s $png); binmode $fh; my $data; sysread($fh, $data, $nbytes) or die "Failed to read data from '$png' ($!)\n"; print "Content-disposition: attachment; filename=$png\n\n"; print $data;