Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting perl statements to mod_perl statements

Status
Not open for further replies.

dwhalen

Programmer
Feb 22, 2002
105
CA
Hey,

I have a mod_perl question. When the user clicks on a link I want them to be able to download a file. Below is the code I use to do it. It works fine. However, I want to make sure I am using mod_perl to it fullest, so I want to convert some of the statments to more mod_perlish (hope that makes sense :) )

This is the middle part of my code

Code:
my $directory = $ENV{"MMS_TEMPORARY_DIRECTORY"};
my $path = $directory.$fileName;

#sending our headers
$r->print("Content-Type: application/vnd.ms-excel\n");
$r->print("Content-Transfer-Encoding: binary\n");
$r->print("Content-Disposition: attachment; filename=\"$fileName\"\n\n");

#creating the excel file.  Creates an excel file at $path
res_report::createExcelFile(\$results,\@titles,\$path,\$header);

#opening our file so we can send it to the client
my $XLS = Symbol::gensym();
open $XLS, "$path" or die "Can't open $path: $!\n";
#setting binmode so the client knows it is binary
binmode( $XLS );
#sending the file
$r->send_fd($XLS);
#close our file off
close($XLS);


The part I think I can change is the sending of the headers:
$r->print("Content-Type: application/vnd.ms-excel\n");
$r->print("Content-Transfer-Encoding: binary\n");
$r->print("Content-Disposition: attachment; filename=\"$fileName\"\n\n");

I think I would change them to:
$r->content_type("application/vnd.ms-excel");
$r->content_encoding("binary");
But what about $r->print("Content-Disposition: attachment; filename=\"$fileName\"\n\n");

Also, am I sending the file correctly??

Thanks for the help.

Later
 
They pretty much equate to the same thing, its basically a style difference so I would not worry to much about it.

Be sure to use strict!

Enjoy mod_perl, I love it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top