Problem reading & displaying MHTML file type

Discussion in 'Perl Misc' started by Robert, Feb 15, 2006.

  1. Robert

    Robert Guest

    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
    Robert, Feb 15, 2006
    #1
    1. Advertising

  2. "Robert" <> wrote in
    news:6DMIf.13589$B94.5803@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 <>
    (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
    A. Sinan Unur, Feb 15, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stream mhtml to browser

    , Dec 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    475
  2. =?Utf-8?B?TUVSNzg=?=

    MHTML Streaming

    =?Utf-8?B?TUVSNzg=?=, Feb 24, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,877
    jgoodale
    Feb 6, 2006
  3. Peter Rilling
    Replies:
    0
    Views:
    392
    Peter Rilling
    Feb 9, 2006
  4. Jason von Bartheld

    Emitting mhtml to browser with ASP.NET

    Jason von Bartheld, May 26, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    288
    Jason von Bartheld
    May 26, 2004
Loading...

Share This Page