|
From: Robert on 15 Feb 2006 15:59 Hi, I have a small piece of code where perl reads an .HTM file and displays it in your browser: #!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; open (FH, "<page.htm") or die &error; my @page = <FH>; close(FH); print "Content-type: text/html \n\n"; print @page; exit; This works totally fine. The problem is now we are working with .MHTML files. Using the code above, when trying to open and display a MHTML file, the contents of the file's source is displayed instead of a formatted page. MHTML files define the Content-type within the file itself at the top and use multipart/related. I tried modifying my code above to that content-type but that didnt work. I'm hoping maybe someone has a suggestion on how I can make this work. Many thanx in advance. Robert
From: A. Sinan Unur on 15 Feb 2006 16:39 "Robert" <rbutcher.nospam(a)hotmail.com> wrote in news:6DMIf.13589$B94.5803(a)pd7tw3no: > Hi, > > I have a small piece of code where perl reads an .HTM file and > displays it in your browser: > > #!/usr/bin/perl > > use CGI qw(:standard); > use CGI::Carp qw(fatalsToBrowser); > use strict; use warnings; missing. $| = 1; is a good idea with CGI scripts. > open (FH, "<page.htm") or die &error; open my $fh, '<', 'page.htm' or die error(); Lexical filehandles and the three argument form of open is generally preferable. &error has specific effects (see perldoc perlsub). If you don't know what those are, you don't need them. > my @page = <FH>; Why slurp the whole file only to print it out print while <$fh>; scales much better. > close(FH); > > print "Content-type: text/html \n\n"; Why use CGI.pm if you are not going to use it. print header('text/html'); > print @page; > exit; exit is completely unnecessary here. > > This works totally fine. So, to wrap it up: open my $html, '<', 'page.htm' or die error(); print header('text/html'); print while <$html>; close $html; > The problem is now we are working with .MHTML files. Using the code > above, when trying to open and display a MHTML file, the contents of > the file's source is displayed instead of a formatted page. MHTML > files define the Content-type within the file itself at the top and > use multipart/related. I tried modifying my code above to that > content-type but that didnt work. I'm hoping maybe someone has a > suggestion on how I can make this work. Many thanx in advance. I don't know anything about mhtml files, but maybe using the correct MIME type would work: print header('message/rfc822'); Sinan -- A. Sinan Unur <1usa(a)llenroc.ude.invalid> (reverse each component and remove .invalid for email address) comp.lang.perl.misc guidelines on the WWW: http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
|
Pages: 1 Prev: random fortune cookie Next: perl/expect.pm manual user input |