0

I am using PCLZIP to create a ZIP that contains few documents and pdfs. On some machine, users are claiming zip to be corrupted.

On my machines, I don't see ZIP to be corrupted, but whenever I try to send that zip via Gmail, it blocks the ZIP saying it contains an executable, but in fact all that zip have are documents and PDF files. So I see relation between people claiming that zip are corrupted and Gmail blocking these zip created from our app.

I have tried extracting all the files and again adding them in a zip using Window's add to archive option. And if I send this zip, gmail doesn't block.

So I believe there has to be some problem when I am creating ZIP in my PHP app.

Here is the relevant portion of the code where I am creating ZIP:

<?php 

$archive = new PclZip("exportZIPs/{$randomFileName}.zip");
$orgFile = $document->sAbsStoragePath.$document->sSysFileName;

$filePath = array();

$filePath[] = array( PCLZIP_ATT_FILE_NAME => $orgFile,
       PCLZIP_ATT_FILE_NEW_FULL_NAME => "{$someNewName}"
    );

foreach ($aList as $key => $value) {


    $filePathTmp = "{$SomePath}.pdf";

    if(!file_exists($filePathTmp)) {
        continue;
    }
    //$filePath[] = "{$SomePath}.pdf";

    $filePath[] = array( PCLZIP_ATT_FILE_NAME => $filePathTmp,
       PCLZIP_ATT_FILE_NEW_FULL_NAME => "PDFs/Version-{$sVersion}.pdf"
    );
}

$v_list = $archive->add($filePath, PCLZIP_OPT_REMOVE_PATH, 'PDFs');
if ($v_list == 0) {
    die("Cannot Create Archive! Try again or contact administrator");
    die("Error : ".$archive->errorInfo(true));
}

header("Content-Type: application/zip");
header("Content-Disposition:attachment;filename=\"{$SOMENAME}.zip\"");

readfile("exportZIPs/{$randomFileName}.zip");

@unlink("exportZIPs/{$randomFileName}.zip");

?>

What am I doing wrong?

4

1 回答 1

0

最后我发现,问题不在于创建存档。发送内容数据时出现问题。

我在代码中添加了以下几行并修复了它:

header("Content-Type: application/octet-stream");

header("Content-Disposition:attachment;filename=\"{$document->iID}-{$document->sName}.zip\"");
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$originalFile = "exportZIPs/{$randomFileName}.zip";
header('Content-Length: ' . filesize($originalFile));
ob_clean();
flush();
readfile("exportZIPs/{$randomFileName}.zip");

@unlink("exportZIPs/{$randomFileName}.zip");

识别这一点的时间太长的原因是 winZIP 和其他 ZIP 应用程序存在自动更正问题,并且没有报告存档已损坏。

于 2014-05-26T08:07:00.867 回答