"Gray, Josh" wrote:
>
> Can someone show me how to go about opening a file (out side of webroot) and
> directing the contents to the user to download ? Thanks :)
Untested in this form:
use strict;
use LWP::MediaTypes;
my $path = '../../gif'; # change me to where downloads are
my $filename = '';
# change this compound if to get the args your way or use CGI.pm or ??
if (defined $ENV{QUERY_STRING}) {
$filename = $ENV{QUERY_STRING};
} elsif (defined $ENV{PATH_INFO}) {
$filename = $ENV{PATH_INFO};
} elsif length $filename < 1;
$filename = $ARGV[0];
}
if (length $filename < 1) {
print "Content-Type: text/plain\n\n";
print "No filename arg given\n";
exit 1;
}
my $media_type = guess_media_type ("$path/$filename");
if (length $media_type < 1) {
print "Content-Type: text/plain\n\n";
print "Can't determine media type\n";
exit 1;
}
my $len = -s "$path/$filename";
print <<EOD;
Content-Type: $media_type; name="$filename"
Content-Disposition: inline; filename=$filename
Content-Length: $len
EOD
open IN, "$path/$filename" or die "Error opening $path/$filename: $!\n";
binmode IN;
binmode STDOUT;
while (<IN>) { print; } # or use sysread to read blocks
close IN;
exit 0;
__END__
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web