FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » ZIP file download
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: ZIP file download [message #175818 is a reply to message #175816] Thu, 27 October 2011 13:39 Go to previous messageGo to previous message
JustWondering is currently offline  JustWondering
Messages: 9
Registered: April 2011
Karma:
Junior Member
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?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Simple PHP script - VMS problem
Next Topic: Standard practice: login pages
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 03:36:23 GMT 2024

Total time taken to generate the page: 0.04105 seconds