SPUG: Re: mod_perl download handler help needed
Ryan Parr
ryanparr at thejamescompany.com
Thu Nov 14 14:31:23 CST 2002
Wouldn't the line:
$r->send_http_header($r->lookup_file($filepath)->content_type);
Get back the text/html content type from your handler? Since this is using a
full sub-request, I assume it would trigger your handler. You may be better
off using a method to determine the mime-type other than Apache's subrequest
function.
----- Original Message -----
From: "Alan" <alan at ufies.org>
To: <spug-list at pm.org>
Sent: Thursday, November 14, 2002 11:52 AM
Subject: SPUG: mod_perl download handler help needed
> Hi folks, been working on a little project and I've run into a bit of a
> snag. What I'm doing is designing a file tracker for a client.
> Basically when someone downloads a a file (/files/foo.pdf) it pops up a
> window, gets a name and email, then (when that is complete) gives them
> the file.
>
> To do this what I've done is put a handler on /files that:
> - checks to make sure the file exists and is readable
> - displays an html page with a form action of /files/$filename and a
> hidden field of 'returnto' set to $filename
> - when the submit button is pressed, it submits back to
> /files/$filename, and because the handler is on /files it catches it
> again
> - if the name and email are not filled in, displays the form again
> - if they are filled in, it sends an email to whoever gets the job of
> watching for file downloads, and then uses the following code to
> display the file:
>
> my $filepath = $r->document_root . "/files/" .
> $params{returnto};
> $r->send_http_header($r->lookup_file($filepath)->content_type);
> my $fh = Apache::gensym();
> open($fh, "$filepath") || return NOT_FOUND;
> $r->send_fd($fh);
> close($fh);
> return OK;
>
> This all works just great..... *until the user tries to download the
> file*. Because the browser doesn't grab from the cache (tried both ie6
> and mozilla) the file that is downloaded is the html form because I
> assume, it's seeing the request again, and sending back the html form.
>
> I've tried sticking the parameters on the URL
> (foo.com/files/foo.pdf?name=abc&email=bcd), but then it seems to send me
> back a file with a mime type of httpd/unix-directory (sending the /files
> directory I'm guessing).
>
> Is there a better way to do this? I'd rather not have the download link
> be something like "download.cgi?file=foo.pdf", but if needed I'll revert
> to that. I'd just rather have it work a little more seamlessly than
> that.
>
> Anyway, if anyone has any ideas I'd love to hear them :)
>
> alan
>
> --
> Alan <alan at ufies.org> - http://arcterex.net
> ---------------------------------------------------------------------
> "The only thing that experience teaches us is that experience teaches
> us nothing. -- Andre Maurois (Emile Herzog)
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
>
>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list