douan3182 2016-08-11 02:06
浏览 3495
已采纳

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

I cannot create a zip file. It gives me this error. A search turned up no results. This is my 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";
  }

Console:

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

Docs: http://php.net/manual/en/book.zip.php

PHP 5.6, Win 8.1, Cygwin 2.5.2

Here is the same in 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
  • 写回答

1条回答 默认 最新

  • dpxo13079 2016-08-12 03:58
    关注

    Since ZipArchive is broken, I used PclZip instead.

    $ composer require 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';
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴