Home > Archive > PERL CGI Beginners > January 2006 > Help with issuing the correct mime headers
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help with issuing the correct mime headers
|
|
| Dermot Paikkos 2006-01-18, 6:55 pm |
| Hi,
I have a script that outputs a file as text to the browser but there
are some inconsistencies in how the browser responds to script.
When the script is run under FF it displays the text and you can
choose to 'Save the page' from the file menu and it is saved as text.
Under IE the page is not displayed at all but a 'Save as' dialogue
box appears, and the type is set to unknown. I could live with that.
However the problem is compounded by the fact that if you choose to
save the file, it will save the file as convert-csv.pl. If you choose
open (and have perl installed) it will try to run convert-csv.pl but
it dosen't exist.
So there are 2 questions really.
1) Is there a way to force IE to display a file as plain text. I am
tried 'text' and 'text/plain' but neither make a difference.
If I have read the correct RFC (rfc2046) it says of the type text:
"text -- textual information. The subtype "plain" in
particular indicates plain text containing no
formatting commands or directives of any sort. Plain
text is intended to be displayed "as-is".
2) How can you use the Content-disposition header to make IE save the
file with another name.
# relevant lines
print $q->header(-type=>'text/plain',
-Content-Disposition=>{type=>'inline',filename=>"$filename"},
);
Any help would be appreciated.
Thanx.
Dp.
========== convert-csv.pl ==========
#!/usr/bin/perl -w
#############
# import a csv file into a tilde separated file or vice-versa
###############
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$CGI::POST_MAX = 1024 * 1000; # Set limit to 1MB
use strict;
use warnings;
use Text::ParseWords;
...snip
else {
my $filename = $q->param('uploaded_file');
my $csv_type = $q->param('filetype');
print $q->header(-type=>'text/plain',
-Content-
Disposition=>{type=>'inline',filename=>"$filename"},
);
my $untainted_filename;
my $type = $q->uploadInfo($filename)->{'Content-Type'};
unless ($type eq 'text/plain' or 'text/html') {
print STDERR "Type = $type\n";
die "Text files only";
}
if (! $filename && $q->cgi_error) {
print $q->header(-status=>$q->cgi_error);
exit 0;
}
(my $tmp_name = $filename) =~ s/\W+/_/g;
if ($tmp_name =~ /^([-\@:\/\\\w.]+)$/) {
$untainted_filename = $1;
}
else {
....snip
| |
| Paul Lalli 2006-01-18, 6:55 pm |
| Dermot Paikkos wrote:
> # relevant lines
> print $q->header(-type=>'text/plain',
> -Content-Disposition=>{type=>'inline',filename=>"$filename"},
> );
Did you check your webserver for any error and warning messages? I'm
guessing not, because if you had, you would have seen:
Argument "Disposition" isn't numeric in subtraction (-)
Argument "-Content" isn't numeric in subtraction (-)
Odd number of elements in hash assignment at
$ perl -MData::Dumper -e"
my @vals = (-type=>'text/plain',
-Content-Disposition=>{type=>'inline',filename=>'file.txt'},);
print Dumper (\@vals);
"
$VAR1 = [
'-type',
'text/plain',
'0',
{
'filename' => undef,
'type' => 'inline'
}
];
Quote your hash keys, unless the key is a single "word". (The
prepended - seems to be an allowed exception to this rule... an
interior - is not).
Paul Lalli
|
|
|
|
|