punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Maniacal Monks,

I must first admit that this is a Perl question only insofar as it is a Perl scriupt producing the output that is causing problems. The problem MAY have nothing to do with the Perl script producing the output.

I have two Perl download scripts that get a Powerpoint file from the server, preceed it by a header, then write out the file line by line. The file headers tell the browser what kind of file it is and what its disposition is. The scripts run on different servers, both UNIX boxes. The important part of the scripts - the file getting, header attaching and file downloading parts - are identical. One script is in fact a copy of the first with the only difference being how the script assembles the output file name.

The headers are intended to, and for some time have successfully, cause MSIE to open the PPT in a new, separate instance of PowerPoint on the user's machine. That is, NOT in the browser. As I said, this has worked perfectly for both scripts for months for dozens of users with various configurations.

The Problem - a user who is running Windows XP, the first I know of, reports that files downloaded from script 1 open as intended, but files downloaded via script 2 on the other server open in the browser. With identical file headers, this is a great mystery, and causes all sorts of functionality problems.

Here are the salient partrs of the script:

$download_filetype = '.ppt'; open(FILE, $template) or dienice("cannot open file $template : $_[0] $ +!"); @LINES = <FILE>; close(FILE); $filename = join('_', $session_id, $download_filetype); print "Content-type: application/vnd.ms-powerpoint\n"; print "Content-Disposition: attachment; filename=$filename\n\n"; for $i (0..$#LINES) { print $LINES[$i]; }

Any ideas will be most welcome.

Forget that fear of gravity,
Get a little savagery in your life.

  • Comment on Different client-side behaviours from two theoretically identical download scripts.
  • Download Code

Replies are listed 'Best First'.
Re: Different client-side behaviours from two theoretically identical download scripts.
by Errto (Vicar) on Nov 30, 2005 at 04:11 UTC
    I've found that the only real way to solve this is to ask the user to make a client-side change - namely, going into their Explorer -> File Types menu and changing the option for PowerPoint files to disable the "browse in same window" choice, which is on be default AFAIK. The only other things I can think of are 1) that the $filename contains some invalid characters (perhaps whitespace or non-ASCII characters) that are confusing IE, or 2) that your script is sending multile Content-type or Content-disposition headers (or your web server is adding them). To check for this, you need to view the headers your client is actually receiving; one easy (and Perlish) way to do this is to set up a local instance of HTTP::Proxy and point your browser to it.
Re: Different client-side behaviours from two theoretically identical download scripts.
by monarch (Priest) on Nov 30, 2005 at 03:40 UTC
    If I ever needed a reason to $!@%$ a Microsoft Employee in the $!@%, IE for XP is many good reasons.

    Microsoft appear to have made XP less standards-compliant than earlier versions of IE.. one of the things that has tripped me up is the necessarity of making the server tell the browser that pages may be cached, otherwise IE for XP will refuse to download the file to open.

    Your use of the Content-Disposition: attachment; appears to be correct so I'm puzzled as to why the IE browser isn't opening in a new window. Just as an aside I would do two new things in your script:

    1. add a Content-Length: $bytes line so that your browser can estimate how long the download will take.

    2. read the file in using read instead of <FILE> as it is a binary file without record separators.. e.g.

    my $template = "filename.ppt"; my $fsize = ( stat( $template ) )[7]; if ( ! open( FILE, "<$template" ) ) { die( "Cannot open $template, $!" ); } print( "Content-Disposition: attachment; filename=\"$template\"\n" ); print( "content-type: application/vnd.ms-powerpoint\n" ); print( "Content-Length: $fsize\n" ); print( "\n" ); my ( $result, $data ); while ( $result = read( FILE, $data, 8192 ) ) { print( $data ); } close( FILE );
Re: Different client-side behaviours from two theoretically identical download scripts.
by xdg (Monsignor) on Nov 30, 2005 at 02:37 UTC

    Could you post a unified diff of the two scripts? That might help a diagnosis.

    (The code style isn't great, but since it's mostly working, I wouldn't mess with it at the moment.)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Different client-side behaviours from two theoretically identical download scripts.
by punch_card_don (Curate) on Dec 01, 2005 at 00:38 UTC
    OK, thanks all for the pointers. I'll try some of this out and cross my fingers.

    Love love, hate Microsoft.

    Forget that fear of gravity,
    Get a little savagery in your life.