Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3594 > unrolled thread

ZIP file download

Started byJustWondering <eastsidedev@gmail.com>
First post2011-10-27 03:29 -0700
Last post2011-10-27 17:54 -0400
Articles 8 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  ZIP file download JustWondering <eastsidedev@gmail.com> - 2011-10-27 03:29 -0700
    Re: ZIP file download Derek Turner <frderek@cesmail.net> - 2011-10-27 10:32 +0000
      Re: ZIP file download JustWondering <eastsidedev@gmail.com> - 2011-10-27 03:47 -0700
      Re: ZIP file download JustWondering <eastsidedev@gmail.com> - 2011-10-27 03:49 -0700
    Re: ZIP file download "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-10-27 14:07 +0200
      Re: ZIP file download JustWondering <eastsidedev@gmail.com> - 2011-10-27 06:39 -0700
        Re: ZIP file download JustWondering <eastsidedev@gmail.com> - 2011-10-27 09:59 -0700
          Re: ZIP file download Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-27 17:54 -0400

#3594 — ZIP file download

FromJustWondering <eastsidedev@gmail.com>
Date2011-10-27 03:29 -0700
SubjectZIP file download
Message-ID<37f1cd74-1fce-4f17-99ed-ab6b36f26179@s32g2000prj.googlegroups.com>
I am trying to write a script to download a zip file. Here's what I
have:

    header("Cache-Control: no-store, no-cache");
    header("Content-Description: File Transfer");
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename="zipfile.zip");
    header("Content-Transfer-Encoding: binary");

    $outstream = fopen("php://output",'w');

    $file = fopen("myfile.zip","rb");
    if ($file) {
      while(!feof($file)) {
          fwrite($outstream, fread($file, 2048));
      }
      fclose($file);
    }
    fclose($outstream);

When I run the script, I get a dialog box asking me to save the file.
The file is saved fine, but I cannot open it from the Windows Explorer
(Windows tells that the compressed file is invalid). 7Zip however has
no problem opening it and extracting the files. Any ideas?

[toc] | [next] | [standalone]


#3595

FromDerek Turner <frderek@cesmail.net>
Date2011-10-27 10:32 +0000
Message-ID<9gsqafFtk4U2@mid.individual.net>
In reply to#3594
On Thu, 27 Oct 2011 03:29:35 -0700, JustWondering wrote:

> I cannot open it from the Windows Explorer
> (Windows tells that the compressed file is invalid). 7Zip however has no
> problem opening it and extracting the files. Any ideas?

What did you use to create myfile.zip? Can windows explorer open that?

[toc] | [prev] | [next] | [standalone]


#3596

FromJustWondering <eastsidedev@gmail.com>
Date2011-10-27 03:47 -0700
Message-ID<d1a6aed9-0777-44bf-a8c6-1fd41fde0a89@q35g2000prh.googlegroups.com>
In reply to#3595
On Oct 27, 3:32 am, Derek Turner <frde...@cesmail.net> wrote:
> On Thu, 27 Oct 2011 03:29:35 -0700, JustWondering wrote:
> > I cannot open it from the Windows Explorer
> > (Windows tells that the compressed file is invalid). 7Zip however has no
> > problem opening it and extracting the files. Any ideas?
>
> What did you use to create myfile.zip? Can windows explorer open that?

I used PHP's zipArchive. Windows explorer can open the file.

[toc] | [prev] | [next] | [standalone]


#3597

FromJustWondering <eastsidedev@gmail.com>
Date2011-10-27 03:49 -0700
Message-ID<9427da31-193f-4746-a786-3ff0d2691380@k13g2000prg.googlegroups.com>
In reply to#3595
On Oct 27, 3:32 am, Derek Turner <frde...@cesmail.net> wrote:
> On Thu, 27 Oct 2011 03:29:35 -0700, JustWondering wrote:
> > I cannot open it from the Windows Explorer
> > (Windows tells that the compressed file is invalid). 7Zip however has no
> > problem opening it and extracting the files. Any ideas?
>
> What did you use to create myfile.zip? Can windows explorer open that?

I should also add that I'm using Windows 7, and FireFox.

[toc] | [prev] | [next] | [standalone]


#3598

From"Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Date2011-10-27 14:07 +0200
Message-ID<j8bhii$q77$1@dont-email.me>
In reply to#3594
El 27/10/2011 12:29, JustWondering escribió/wrote:
> I am trying to write a script to download a zip file. Here's what I
> have:
>
>      header("Cache-Control: no-store, no-cache");
>      header("Content-Description: File Transfer");
>      header("Content-Type: application/octet-stream");
>      header("Content-Disposition: attachment; filename="zipfile.zip");

You have an unmatched quote so I guess this is not the literal code your 
are running. Make sure that the real code does not add bogus white-space 
before of after the file. You can test that if you open the file in an 
hexadecimal editor (though a regular editor may do the trick).

You can end up with a bogus byte if you've saved the PHP source as UTF-8 
and your editor is configured to write the Unicode BOM (byte-order marker).


>      header("Content-Transfer-Encoding: binary");
>
>      $outstream = fopen("php://output",'w');
>
>      $file = fopen("myfile.zip","rb");
>      if ($file) {
>        while(!feof($file)) {
>            fwrite($outstream, fread($file, 2048));
>        }
>        fclose($file);
>      }
>      fclose($outstream);
>
> When I run the script, I get a dialog box asking me to save the file.
> The file is saved fine, but I cannot open it from the Windows Explorer
> (Windows tells that the compressed file is invalid). 7Zip however has
> no problem opening it and extracting the files. Any ideas?




-- 
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

[toc] | [prev] | [next] | [standalone]


#3600

FromJustWondering <eastsidedev@gmail.com>
Date2011-10-27 06:39 -0700
Message-ID<20c16273-bb06-4366-ba8a-c0b7277f2a81@f3g2000pri.googlegroups.com>
In reply to#3598
On Oct 27, 5:07 am, "Álvaro G. Vicario"
<alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:
> El 27/10/2011 12:29, JustWondering escribió/wrote:
>
> > I am trying to write a script to download a zip file. Here's what I
> > have:
>
> >      header("Cache-Control: no-store, no-cache");
> >      header("Content-Description: File Transfer");
> >      header("Content-Type: application/octet-stream");
> >      header("Content-Disposition: attachment; filename="zipfile.zip");
>
> You have an unmatched quote so I guess this is not the literal code your
> are running. Make sure that the real code does not add bogus white-space
> before of after the file. You can test that if you open the file in an
> hexadecimal editor (though a regular editor may do the trick).
>
> You can end up with a bogus byte if you've saved the PHP source as UTF-8
> and your editor is configured to write the Unicode BOM (byte-order marker).
>
>
>
>
>
>
>
>
>
> >      header("Content-Transfer-Encoding: binary");
>
> >      $outstream = fopen("php://output",'w');
>
> >      $file = fopen("myfile.zip","rb");
> >      if ($file) {
> >        while(!feof($file)) {
> >            fwrite($outstream, fread($file, 2048));
> >        }
> >        fclose($file);
> >      }
> >      fclose($outstream);
>
> > When I run the script, I get a dialog box asking me to save the file.
> > The file is saved fine, but I cannot open it from the Windows Explorer
> > (Windows tells that the compressed file is invalid). 7Zip however has
> > no problem opening it and extracting the files. Any ideas?
>
> --
> --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web:http://borrame.com
> -- Mi web de humor satinado:http://www.demogracia.com
> --

In the real code, U have a variable where the file names are. I
replaced that with actual file names to avoid any confusion. I guess
in the process I messed up the quotes.

In any case, I opened up the downloaded file in a binary editor and
found that the entire HEAD section is added upfront (names of style
sheets, description, etc.). How do I prevent this from happening?

[toc] | [prev] | [next] | [standalone]


#3603

FromJustWondering <eastsidedev@gmail.com>
Date2011-10-27 09:59 -0700
Message-ID<e489ed56-cb47-4af5-90be-51299c907c87@z28g2000pro.googlegroups.com>
In reply to#3600
On Oct 27, 6:39 am, JustWondering <eastside...@gmail.com> wrote:
> On Oct 27, 5:07 am, "Álvaro G. Vicario"
>
>
>
>
>
>
>
>
>
> <alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:
> > El 27/10/2011 12:29, JustWondering escribió/wrote:
>
> > > I am trying to write a script to download a zip file. Here's what I
> > > have:
>
> > >      header("Cache-Control: no-store, no-cache");
> > >      header("Content-Description: File Transfer");
> > >      header("Content-Type: application/octet-stream");
> > >      header("Content-Disposition: attachment; filename="zipfile.zip");
>
> > You have an unmatched quote so I guess this is not the literal code your
> > are running. Make sure that the real code does not add bogus white-space
> > before of after the file. You can test that if you open the file in an
> > hexadecimal editor (though a regular editor may do the trick).
>
> > You can end up with a bogus byte if you've saved the PHP source as UTF-8
> > and your editor is configured to write the Unicode BOM (byte-order marker).
>
> > >      header("Content-Transfer-Encoding: binary");
>
> > >      $outstream = fopen("php://output",'w');
>
> > >      $file = fopen("myfile.zip","rb");
> > >      if ($file) {
> > >        while(!feof($file)) {
> > >            fwrite($outstream, fread($file, 2048));
> > >        }
> > >        fclose($file);
> > >      }
> > >      fclose($outstream);
>
> > > When I run the script, I get a dialog box asking me to save the file.
> > > The file is saved fine, but I cannot open it from the Windows Explorer
> > > (Windows tells that the compressed file is invalid). 7Zip however has
> > > no problem opening it and extracting the files. Any ideas?
>
> > --
> > --http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
> > -- Mi sitio sobre programación web:http://borrame.com
> > -- Mi web de humor satinado:http://www.demogracia.com
> > --
>
> In the real code, U have a variable where the file names are. I
> replaced that with actual file names to avoid any confusion. I guess
> in the process I messed up the quotes.
>
> In any case, I opened up the downloaded file in a binary editor and
> found that the entire HEAD section is added upfront (names of style
> sheets, description, etc.). How do I prevent this from happening?

Problem solved. Here's what I did:

    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-
check=0");
    header("Content-Description: File Transfer");
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"targetfile.zip
\"");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . filesize('sourcefile.zip'));
    ob_clean();
    flush();
    readfile ('sourcefile.zip');

[toc] | [prev] | [next] | [standalone]


#3606

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-27 17:54 -0400
Message-ID<j8cjuo$l20$1@dont-email.me>
In reply to#3603
On 10/27/2011 12:59 PM, JustWondering wrote:
> On Oct 27, 6:39 am, JustWondering<eastside...@gmail.com>  wrote:
>> On Oct 27, 5:07 am, "Álvaro G. Vicario"
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> <alvaro.NOSPAMTH...@demogracia.com.invalid>  wrote:
>>> El 27/10/2011 12:29, JustWondering escribió/wrote:
>>
>>>> I am trying to write a script to download a zip file. Here's what I
>>>> have:
>>
>>>>       header("Cache-Control: no-store, no-cache");
>>>>       header("Content-Description: File Transfer");
>>>>       header("Content-Type: application/octet-stream");
>>>>       header("Content-Disposition: attachment; filename="zipfile.zip");
>>
>>> You have an unmatched quote so I guess this is not the literal code your
>>> are running. Make sure that the real code does not add bogus white-space
>>> before of after the file. You can test that if you open the file in an
>>> hexadecimal editor (though a regular editor may do the trick).
>>
>>> You can end up with a bogus byte if you've saved the PHP source as UTF-8
>>> and your editor is configured to write the Unicode BOM (byte-order marker).
>>
>>>>       header("Content-Transfer-Encoding: binary");
>>
>>>>       $outstream = fopen("php://output",'w');
>>
>>>>       $file = fopen("myfile.zip","rb");
>>>>       if ($file) {
>>>>         while(!feof($file)) {
>>>>             fwrite($outstream, fread($file, 2048));
>>>>         }
>>>>         fclose($file);
>>>>       }
>>>>       fclose($outstream);
>>
>>>> When I run the script, I get a dialog box asking me to save the file.
>>>> The file is saved fine, but I cannot open it from the Windows Explorer
>>>> (Windows tells that the compressed file is invalid). 7Zip however has
>>>> no problem opening it and extracting the files. Any ideas?
>>
>>> --
>>> --http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
>>> -- Mi sitio sobre programación web:http://borrame.com
>>> -- Mi web de humor satinado:http://www.demogracia.com
>>> --
>>
>> In the real code, U have a variable where the file names are. I
>> replaced that with actual file names to avoid any confusion. I guess
>> in the process I messed up the quotes.
>>
>> In any case, I opened up the downloaded file in a binary editor and
>> found that the entire HEAD section is added upfront (names of style
>> sheets, description, etc.). How do I prevent this from happening?
>
> Problem solved. Here's what I did:
>
>      header("Pragma: public");
>      header("Expires: 0");
>      header("Cache-Control: must-revalidate, post-check=0, pre-
> check=0");
>      header("Content-Description: File Transfer");
>      header("Content-Type: application/octet-stream");
>      header("Content-Disposition: attachment; filename=\"targetfile.zip
> \"");
>      header("Content-Transfer-Encoding: binary");
>      header("Content-Length: " . filesize('sourcefile.zip'));
>      ob_clean();
>      flush();
>      readfile ('sourcefile.zip');

It's much easier than that.  Just don't put a HEAD section in there.

<HEAD> is for (X)HTML.  You are sending a zip file.  Not at all the same 
thing.

Your script should ONLY contain (starting on line 1):

<?php
   header(...)
    etc. ...
   readfile('sourcefile.zip')
?>



-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web