2016-08-29 9 views
2

これは新しいリリースのバグかもしれません。あるいは、何かがZipArchiveの動作を変更して、私のコードが古いものですが、CREATEフラグがOVERWRITEフラグが使用されるとブレークします。これは、PHP 5.6の下でうまくいきましたが、PHP 7.0の下で、私は次のエラーを取得:PHP 7 ZipArchive :: OVERWRITEが動作しない

Warning: ZipArchive::close(): Invalid or uninitialized Zip object 

オリジナルコード:

foreach(glob($sourcedir.'*.[zZ][iI][pP]') as $zippath) 
{ 
    // create daily zip file 
    $zipname = preg_replace('~'.$sourcedir.'~','',$zippath); 
    $zipname2 = preg_replace('~\.zip~','',$zipname); 

    $zip = new ZipArchive(); 
    $ret = $zip->open($xmlzip.$zipname2.'_contact_xml.zip', ZipArchive::OVERWRITE); 

    // move xml files to daily zip file created above 
    if ($ret !== TRUE) { 
     printf('Failed with code %d', $ret); 
    } else { 

     foreach(glob($source_file_path.'*.[xX][mM][lL]') as $xmlpath){ 
     $zip->addFile($xmlpath, preg_replace('~'.$source_file_path.'~','',$xmlpath)); 
     } 

    } 

    $zip->close(); 
} 

任意のアイデア?

答えて

6

フラグとしてZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITEをフラグとして渡します。

それはバグです:https://bugs.php.net/bug.php?id=71064(PHP 5.6.16以降)

There is an issue with the ZipArchive class' open() method. In previous versions of PHP when the only flag passed to the method was the ZipArchive::OVERWRITE , the method also created non-existing archives.

Since PHP 5.6 the OVERWRITE flag alone cannot create new archives which breaks compatibility.

+0

作品!あなたはどちらか一方だけを渡さなければならないと思った。 – photocode

+1

@photocode更新された回答を参照してください。それはバグです。 – Gordon

関連する問題