Problem reading & displaying MHTML file type

R

Robert

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
 
A

A. Sinan Unur

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top