Arnaud DHENRY
Arnaud DHENRY

Reputation: 19

Downloading corrupt .zip (php)

binaryhere is my problem I'm working with php, I create a zip archive thx to ZipArchive library. I complete it with all files I need and save it on my server. Then I want to make it download by the current user, here is what I wrote :

if (file_exists($zip_archive))
{
    header("Pragma: no-cache");
    header("Expires: 0");
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-type: application/force-download");
    header("Content-Disposition: attachment; filename=\"".$zip_archive."\"");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($zip_archive));
ob_end_flush();
    readfile($zip_archive);
}   

But when I download the zip archive, I can see files inside, but when I try to extract them, an error occurs telling me that the file might be corrupted.

So I tried to open the zip archive saved on the server, and NO error appears.

Have you got any idea to help me ?

Thanks for any help.

(I changed fichier to binary, but a problem persists : End of archive ...)

Upvotes: 1

Views: 938

Answers (1)

PiranhaGeorge
PiranhaGeorge

Reputation: 999

This line:

header("Content-Transfer-Encoding: fichier");

Should read:

header("Content-Transfer-Encoding: binary");

You can read more about this header at http://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html. There is also a list of available encoding types, suffice to say 'fichier' isn't there.

Upvotes: 1

Related Questions