使用PharData或ZipArchive创建压缩文件的问题

时间:2019-05-14 21:55:42

标签: php http zip

多年来,以下代码已在同一硬件上的4个并行安装中从PDF文件创建zip文件。

一个星期以来,单个系统不再起作用,因此无需更改代码。

通过浏览器下载的文件有一个损坏的存档,当您手动将文件结尾从“ .zip”更改为“ .pdf”时,它便是一个正常的pdf文件。

似乎文件是在zip创建就绪之前发送的,因为我可以通过ftp从服务器光盘上的creation文件夹中通过ftp下载存档的工作副本。

我试图在返回之前添加一个sleep(5),注释掉了PharData的使用,但没有任何效果。还是同样的问题。有什么想法吗?

<?php

//use phar class to zip, if existent
if ( class_exists( 'PharData' ) ) {

    $a = new PharData( $path );

    foreach ( $creditmemo_files as $creditmemo_file ) {
        if ( is_string( $creditmemo_file ) ) {
            $a->addFile( $creditmemo_file, basename( $creditmemo_file ) );
        }

    }

}
//otherwise use the usual zip archive class
if ( class_exists( 'ZipArchive' ) ) {

    create_zip( $creditmemo_files, $path );

}


if ( file_exists( $path ) === true ) {

    // http headers for zip downloads
    header( "Pragma: public" );
    header( "Expires: 0" );
    header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
    header( "Cache-Control: public" );
    header( "Content-Description: File Transfer" );
    header( "Content-Type: application/zip" );
    header( "Content-Disposition: attachment; filename=\"" . $filename . "\"" );
    header( "Content-Transfer-Encoding: binary" );
    header( "Content-Length: " . filesize( $path ) );
    $bytes_read = readfile( $path );
    ob_end_flush();

}

0 个答案:

没有答案