in reply to Viewing .dat files
As shown above, you name this snippet eg. "plain" and invoke it by#!/usr/bin/perl # [plain] (no extension) # dump some /cgi-bin/ (or other) file in plaintext mode # 1) file must be in the same dir as script # 2) server has to provide PATH_INFO # 3) call with: http://my.server.org/cgi-bin/plain/textfile.dat # if 'plain' is the scripts name # my ($fn) = $ENV{SCRIPT_FILENAME} =~ /(.+?)[^\/]+$/g; $fn .= $1 if $ENV{PATH_INFO} =~ /([^\/]+)$/; print "Content-type: text/plain\n\n"; if( -f $fn ) { open my $fh, '<', $fn or warn "$!"; local $/; print <$fh> } else { print "($fn not found)\n" }
|
|---|