Serving ZIP files to IE using PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Ellsworth

    Serving ZIP files to IE using PHP

    Hi,
    I've been wrestling for several months now with this issue in IE:
    Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


    (IE thinks that ZIPs sent from a script are corrupt when they are not).
    IE now also seems to think that many other files are ActiveX controls
    and pops up the "Some files may damage your computer...Open Save
    Cancel" dialog.

    However, I am quite certain that others have managed to use a script
    serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
    do just that a moment ago.

    I am currently using IIS and a Windows-ized version of mod_rewrite to do
    URL rewriting so that IE in theory should not know that it is receiving
    a ZIP file from script. Nonetheless, the error occurs even with
    rewriting invoked. The problem seems to be that after IE pops up its
    security dialog, it does not issue another HTTP request, but seems to
    expect to go get the file.

    Can anyone give me advice on how to do this? A tutorial, a newsgroup
    thread, anything would be useful...

    Thanks,

    Eric
  • Ian.H

    #2
    Re: Serving ZIP files to IE using PHP

    On Wed, 31 Mar 2004 12:12:08 -0500, Eric Ellsworth wrote:
    [color=blue]
    > However, I am quite certain that others have managed to use a script
    > serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
    > do just that a moment ago.[/color]


    Eric..

    I coded this function a long time ago that works without issue with ZIP
    files (just tried it with IE6 too):


    function download($file) {
    if (empty($file) || !@file_exists($ file)) return false;

    @header('Conten t-type: archive/tar');
    @header('Conten t-length: ' . @filesize($file ));
    @header('Conten t-disposition: attachment; filename=' .
    array_pop(split ('/', $file)));
    @header('Conten t-transfer-encoding: binary'); @readfile($file );

    return true;
    }


    $file in this case is a complete path name hence the array_pop() and
    split() calls to retrieve just the filename to send as the file to be
    saved.

    Hope this is at least of some help to you =)



    Regards,

    Ian


    [XP trimmed (php.lang not available on my news server)]

    --
    Ian.H
    digiServ Network
    London, UK


    Comment

    • Manuel Lemos

      #3
      Re: Serving ZIP files to IE using PHP

      On 03/31/2004 02:12 PM, Eric Ellsworth wrote:[color=blue]
      > I've been wrestling for several months now with this issue in IE:
      > http://support.microsoft.com/?kbid=308090
      >
      > (IE thinks that ZIPs sent from a script are corrupt when they are not).
      > IE now also seems to think that many other files are ActiveX controls
      > and pops up the "Some files may damage your computer...Open Save Cancel"
      > dialog.
      >
      > However, I am quite certain that others have managed to use a script
      > serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
      > do just that a moment ago.
      >
      > I am currently using IIS and a Windows-ized version of mod_rewrite to do
      > URL rewriting so that IE in theory should not know that it is receiving
      > a ZIP file from script. Nonetheless, the error occurs even with
      > rewriting invoked. The problem seems to be that after IE pops up its
      > security dialog, it does not issue another HTTP request, but seems to
      > expect to go get the file.
      >
      > Can anyone give me advice on how to do this? A tutorial, a newsgroup
      > thread, anything would be useful...[/color]

      There is nothing that can be done except for telling the user to save
      the file and open it later.

      --

      Regards,
      Manuel Lemos

      PHP Classes - Free ready to use OOP components written in PHP
      Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


      PHP Reviews - Reviews of PHP books and other products


      Metastorage - Data object relational mapping layer generator

      Comment

      • Eric Ellsworth

        #4
        Re: Serving ZIP files to IE using PHP

        Hi Ian,
        Thanks for the quick reply - I will try using your code. Do you mind
        if I ask why you used the @'s in front of the header function?

        Thanks,

        Eric

        Ian.H wrote:
        [color=blue]
        > On Wed, 31 Mar 2004 12:12:08 -0500, Eric Ellsworth wrote:
        >
        >[color=green]
        >>However, I am quite certain that others have managed to use a script
        >>serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
        >>do just that a moment ago.[/color]
        >
        >
        >
        > Eric..
        >
        > I coded this function a long time ago that works without issue with ZIP
        > files (just tried it with IE6 too):
        >
        >
        > function download($file) {
        > if (empty($file) || !@file_exists($ file)) return false;
        >
        > @header('Conten t-type: archive/tar');
        > @header('Conten t-length: ' . @filesize($file ));
        > @header('Conten t-disposition: attachment; filename=' .
        > array_pop(split ('/', $file)));
        > @header('Conten t-transfer-encoding: binary'); @readfile($file );
        >
        > return true;
        > }
        >
        >
        > $file in this case is a complete path name hence the array_pop() and
        > split() calls to retrieve just the filename to send as the file to be
        > saved.
        >
        > Hope this is at least of some help to you =)
        >
        >
        >
        > Regards,
        >
        > Ian
        >
        >
        > [XP trimmed (php.lang not available on my news server)]
        >[/color]

        Comment

        • Ian.H

          #5
          Re: Serving ZIP files to IE using PHP

          [ Thread rearranged into chronological order ]
          [color=blue]
          > Ian.H wrote:[/color]


          [ snip ]
          [color=blue][color=green]
          >> function download($file) {
          >> if (empty($file) || !@file_exists($ file)) return false;
          >>
          >> @header('Conten t-type: archive/tar');
          >> @header('Conten t-length: ' . @filesize($file ));
          >> @header('Conten t-disposition: attachment; filename=' .
          >> array_pop(split ('/', $file)));
          >> @header('Conten t-transfer-encoding: binary'); @readfile($file );
          >>
          >> return true;
          >> }[/color][/color]


          [ snip ]


          On Mon, 05 Apr 2004 16:22:52 -0400, Eric Ellsworth wrote:
          [color=blue]
          > Hi Ian,
          > Thanks for the quick reply - I will try using your code. Do you mind
          > if I ask why you used the @'s in front of the header function?
          >
          > Thanks,[/color]


          No probs at all.. hope it helps you =)

          The @ char before a function in PHP supresses any errors/ warnings that
          function may produce.

          We're not looking for browser output here and I don't need the error
          checking in the function (the way I used/ coded it anyway) as this is done
          separately.. so to keep PHP quiet just incase.. I supressed the output.

          For the actual checking.. I'd do something like:


          <?php
          [...]

          if (is_readable($f ile)) {
          download($file) ;
          } else {
          /* Throw some kind of error about problem reading file... */
          }

          [...]
          ?>


          or something along those lines. The reason the "validation " was done
          outside of the function as it was part of a much larger script and had
          other considerations I needed to take into consideration etc =)



          Regards,

          Ian

          --
          Ian.H
          digiServ Network
          London, UK


          Comment

          • Brendan Donahue

            #6
            Re: Serving ZIP files to IE using PHP

            Eric Ellsworth wrote:
            [color=blue]
            > Hi,
            > I've been wrestling for several months now with this issue in IE:
            > http://support.microsoft.com/?kbid=308090
            >
            > (IE thinks that ZIPs sent from a script are corrupt when they are not).
            > IE now also seems to think that many other files are ActiveX controls
            > and pops up the "Some files may damage your computer...Open Save
            > Cancel" dialog.
            >
            > However, I am quite certain that others have managed to use a script
            > serve ZIPs, PPTs or PDF files to clients using IE, as I saw download.com
            > do just that a moment ago.
            >
            > I am currently using IIS and a Windows-ized version of mod_rewrite to do
            > URL rewriting so that IE in theory should not know that it is receiving
            > a ZIP file from script. Nonetheless, the error occurs even with
            > rewriting invoked. The problem seems to be that after IE pops up its
            > security dialog, it does not issue another HTTP request, but seems to
            > expect to go get the file.
            >
            > Can anyone give me advice on how to do this? A tutorial, a newsgroup
            > thread, anything would be useful...
            >
            > Thanks,
            >
            > Eric[/color]
            Exactly what code have you tried?
            If this isn't what you did, you could sent a content-type header telling the
            browser you are sending a ZIP file, or maybe try the content-type
            application/octet-stream

            Comment

            • Cecile Muller

              #7
              Re: Serving ZIP files to IE using PHP

              > Do you mind if I ask why you used the @'s in front of the header function?

              So that it doesn't "complain" if the headers were already sent (aka
              not output php's error text).

              Comment

              Working...