SPUG: mod_perl download handler help needed

Alan alan at ufies.org
Thu Nov 14 13:52:16 CST 2002

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
 - 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/" .
		my $fh = Apache::gensym();
		open($fh, "$filepath") || return NOT_FOUND;
		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

Anyway, if anyone has any ideas I'd love to hear them :)


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

More information about the spug-list mailing list