-
Securing those environment variables is not needed, since you don't spawn any kids.
-
You're using the wrong MIME type for "JPEG" images. It's should be image/jpeg.
-
die is not very appropriate for CGI scripts.
-
exit is not needed.
-
sysread is probably more appropriate, but I find $/ = \2048 and $/ = \$buffer_size neat:
local $/ = \2048;
open(my $fh, '<', $path) or die "Failed to open $path: $!";
binmode($fh);
binmode(STDOUT);
print while <$fh>;
| [reply] [Watch: Dir/Any] [d/l] [select] |
Sometimes I also do session verification, which is why the environment variables crept in, so I suppose that's best left to what ever external code needs to be called. I'd skip the use CGI alltogether, but depending on how I need to get the path, it's usually there anyway. Speaking of CGI, I suppose it would be faster to skip CGI as well and simply print the headers directly?
For an image dump, what would you suggest to end the script other than die? My thinking is the output of die never makes it to the client (at least not in any readable way, 'cause it's an image), but you at least get the results in the Apache error logs. I suppose that could be considered either good or bad.
Your $/ trick is very clever. I like it. But is it any better/worse on performance? Dumping images is such a lowly task for Perl. I'd hate to waste anymore cycles then absolutely necessary doing it :)
| [reply] [Watch: Dir/Any] |