I have a zip fie that is good and works when extracting.
When I download the same file it gets corrupted.
The size downloaded is correct, but it does not work.
Error message:
"Can not open the file as zip archive.
Is not archive"

My download code is:
$path = 'zipfile/images.zip';
$type = mime_content_type($path);
header('Content-Type: '.$type);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Content-Length: '.filesize($path));
readfile($path);

    If you open the downloaded file using a programming editor, I would bet that there are some character(s) at the beginning of it due to output having been produced by the web page this code is part of, combined with php's output_buffering being turned on in your php.ini.

    You are right!
    I had a <h4>title</h4> on top of download page.
    This title was seen as the first in the corrupt zip file.
    When I disabled the page title, everything is alright and the zip is now corrrect.
    Thanks very much.

      Write a Reply...