With mod_perl and Apache::File, this is rather easy:
use Apache::Constants qw(:common);
use Apache::Request;
use Apache::File;
sub handler {
my $r = Apache::Request->new(shift);
my $serverFile = $r->param('file');
# needs some errorhandling here if $serverFile is not
# submitted, invalid paths, ...
# get $contenttype somehow; I always save it in a
# database when I upload the file
my $fh = Apache::File->new($serverFile);
binmode($fh);
unless ($fh) {
$r->log_error("Can't open '$serverFile': $!");
} # unless
else {
$r->send_http_header($contenttype);
$r->send_fd($fh);
} # else
return OK;
} # handler
well, you'll need to do some errorhandling...
If you use a temporary filename at the server, it is not so easy to tell the client to save the file under the original filename. I like to use mod_rewrite (httpd.conf) or PerlTransHandler to prevent this and which could look like:
RewriteEngine on
RewriteRule /download/(.+)/(.*) /perl-bin/download.pl?file=$1;$2
There $1 is the temporary filename and $2 the original filename. Or with PerlTransHandler:
package TransHandler;
use warnings;
use strict;
use Apache::Constants qw(DECLINED);
sub handler {
my $r = shift;
my $standardUri = "/pboard/PBoard.pm";
my $uri = $r->uri();
if ($uri =~ m|^/download/([^/]+)/(.+)|) {
$r->uri($standardUri);
$r->args("action=download2;file=$1");
return DECLINED;
} # elsif
return DECLINED;
} # handler
Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"
|