Re: Corrupted ZIP files (downloaded via a php script) : Internext Explorer 7

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



robert mena wrote:
Hi,

I have a set of files stored in a directory and I need to serve those via a
php script (in order to protect, control access etc).

The problem is that zip files (exe also) get corrupted when I try from IE7.
 I've read the posts from this list and google etc with no idea of how to
solve it.

The stored files are ok (tested from firefox or direct copy).  When I use
IE7 the file size is smaller.  In my test a config.zip with 248 bytes ends
up with 214 bytes.

This is the code used

header("Pragma: public");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: ".$type);

if($remove_date_from_file == false)
    header('Content-Disposition: attachment;
filename="'.basename($file).'"');
 else
  {
         $name_ = substr(basename($file),0,strrpos(basename($file),"."));
         $ext_ = substr(basename($file),strrpos(basename($file),"."));
         $new_name_ = substr($name_,0,strlen($name_)-15).$ext_;
         header('Content-Disposition: attachment;
filename="'.$new_name_.'"');
 }
 header("Content-Transfer-Encoding: binary");
 header('Content-Length: '.filesize($file));
 while(!feof($fp))
 {
     echo fgets($fp) ;
 }
 fclose($fp);

I've added a debug to send me a message with the header and it comes the
same way no matter what browser.


Pragma: public

Expires: Wed, 16 Jul 2008 23:12:00 GMT

Cache-Control: must-revalidate, post-check=0, pre-check=0

Cache-Control: private

Content-Type: application/zip

Content-Disposition: attachment; filename="config.zip"

Content-Transfer-Encoding: binary

Content-Length: 248

Am I doing something wrong or do I have to start looking to the server's
configuration (like mod_deflate)?


Instead of that looping through every byte, have you tried just using the readfile() function?

In fact, in that code you posted I don't see you opening the file (where does $fp come from?) Also in your code, you don't flush the file before closing (fflush($fp)), which might make a difference, especially since your result seems to be a few bytes short.

Oh, and make VERY sure that there is *nothing* output to the client before you start pushing the ZIP file out - that definitely leads to corruption of such things, although if you were sending data before changing the headers you would get an error message about that.

What I can't understand is why is might work with one browser and not another...

--
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux