I
IanW
Hi
I know this is not strictly a Perl question (ie: more to do with the usage
of the CGI module) but couldn't get anything from the ciwac group:
I have a Perl script that facilitates the download of files in a non-web
directory. when the follow the url to teh file they will first be presented
with a login page. On that login page is an option to store the login
details in a cookie. so asssuming they say yes to the cookie option the
following code is activated:
# store login details in cookie after manual login
if($fd{store} eq "yes"){
my $cookie = $query->cookie (
-name => 'FALOGIN',
-value => "$email-$password",
-path => '/',
-expires => '+1y'
);
print $query->header(-cookie => $cookie);
}
That works fine, except straight after that code is executed the script them
attempts to send them the file:
if(open(FH,"$fd{f}"){
(my $filename = $fd{f}) =~ s/^.*\///;
if($filename =~ /\.html*$/i){
print "Content-type:text/html\n\n";
elsif($filename =~ /\.jpg$/i){
print "Content-type:image/jpeg\n\n";
}
else{
print "Content-type: application/octet-stream\n";
print "Content-disposition: attachment;
filename=$filename\n\n";
binmode FH;
}
print while <FH>;
}
So, the script decides what type of file it is and chooses the appropriate
content type to send to the browser.
However, it seems that the "print $query->header(-cookie => $cookie);" line
includes a "print "Content-type:text/html\n\n";
" because when I try to access a test document, I get something like this
in my browser:
"Content-type: application/octet-stream Content-disposition: attachment;
filename=test.doc ÐÏࡱá>þÿ !#þÿÿÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿì¥Á%
¿bjbjÞøÞø " ¼'¼'ÿÿÿÿÿÿ]'''''''¦¦¦¦¦ ²
¦U¶ÊÊÊÊÊÊÊÊ$"
Is there a way round this? ie: saving the cookie without printing a
content-type?
Ian
I know this is not strictly a Perl question (ie: more to do with the usage
of the CGI module) but couldn't get anything from the ciwac group:
I have a Perl script that facilitates the download of files in a non-web
directory. when the follow the url to teh file they will first be presented
with a login page. On that login page is an option to store the login
details in a cookie. so asssuming they say yes to the cookie option the
following code is activated:
# store login details in cookie after manual login
if($fd{store} eq "yes"){
my $cookie = $query->cookie (
-name => 'FALOGIN',
-value => "$email-$password",
-path => '/',
-expires => '+1y'
);
print $query->header(-cookie => $cookie);
}
That works fine, except straight after that code is executed the script them
attempts to send them the file:
if(open(FH,"$fd{f}"){
(my $filename = $fd{f}) =~ s/^.*\///;
if($filename =~ /\.html*$/i){
print "Content-type:text/html\n\n";
elsif($filename =~ /\.jpg$/i){
print "Content-type:image/jpeg\n\n";
}
else{
print "Content-type: application/octet-stream\n";
print "Content-disposition: attachment;
filename=$filename\n\n";
binmode FH;
}
print while <FH>;
}
So, the script decides what type of file it is and chooses the appropriate
content type to send to the browser.
However, it seems that the "print $query->header(-cookie => $cookie);" line
includes a "print "Content-type:text/html\n\n";
" because when I try to access a test document, I get something like this
in my browser:
"Content-type: application/octet-stream Content-disposition: attachment;
filename=test.doc ÐÏࡱá>þÿ !#þÿÿÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿì¥Á%
¿bjbjÞøÞø " ¼'¼'ÿÿÿÿÿÿ]'''''''¦¦¦¦¦ ²
¦U¶ÊÊÊÊÊÊÊÊ$"
Is there a way round this? ie: saving the cookie without printing a
content-type?
Ian