PHP:ZipArchive :: close():重命名临时文件失败:没有这样的文件或目录

我无法创build一个zip文件。 它给了我这个错误。 search没有结果。 这是我的function。

function CompressFile($fromExtractedFile) { $archive = new ZipArchive; if ($archive->open($fromExtractedFile.".zip", ZipArchive::OVERWRITE | ZipArchive::CREATE) === TRUE) { $archive->addFile($fromExtractedFile, 'payload.csv'); $archive->close(); } else { throw new Exception ("Compress operation to ZIP file failed. $fromExtractedFile -> $fromExtractedFile.zip"); } return $fromExtractedFile.".zip"; } 

安慰:

 Compressing /tmp/bing_PeUYiT PHP Warning 'yii\base\ErrorException' with message 'ZipArchive::close(): Renaming temporary file failed: No such file or directory' 

文档: http : //php.net/manual/en/book.zip.php

PHP 5.6,Win 8.1,Cygwin 2.5.2

这在PsySh中也是一样的:

 >>> $archive = new ZipArchive => ZipArchive {#199 +"status": 0, +"statusSys": 0, +"numFiles": 0, +"filename": "", +"comment": "", } >>> $archive->open('/tmp/bing_PeUYiT.zip', ZipArchive::OVERWRITE|ZipArchive::CREATE) => true >>> $archive->addFile('/tmp/bing_PeUYiT', 'payload.csv') => true >>> $archive->close() PHP warning: ZipArchive::close(): Renaming temporary file failed: No such file or directory on line 1 

由于ZipArchive被破坏,我用PclZip代替。

$ composer需要pclzip / pclzip

  function compressFile2($file) { $zip = new PclZip($file.'.zip'); $error = $zip->create([[PCLZIP_ATT_FILE_NAME => $file, PCLZIP_ATT_FILE_NEW_FULL_NAME => 'payload.csv']]); # array of array #$error = $zip->create($file, PCLZIP_OPT_REMOVE_ALL_PATH); if ($error == 0) trigger_error("Error : ".$zip->errorInfo(true)); return $file.'.zip'; }