dqz7636 2019-05-25 20:55
浏览 29

为什么这个zip函数忽略/跳过文件?

I have built an application which uploads HTML canvas elements to a directory on the server, and then zips and downloads that directory.

The first part of this (uploading the canvas elements) is working perfectly. All of the .png files are uploaded 100% of the time. However, whenever I come to zip and download the directory contents, it seems that files are being missed/skipped.

Here is the code I'm using to zip the directory:

if($x == $l) { // $x = number of .PNGs, $l = expected number
  $zip = new ZipArchive();
  $zipPath = "../titles/" . $folder . ".zip";
  if ($zip->open($zipPath, ZIPARCHIVE::CREATE )!==TRUE) {
    exit("cannot open" . $zipPath> . "
");
  }

  $list = scandir($path);
  foreach($list as $value) {
  $ex = explode(".", $value);
    if($ex[1]=="png") {
      $zip->addFile($path.$value, $value);
    }
  }

  $zip->close();
  echo "titles/" . $folder . ".zip"; // Sends path back to browser for download
}

There is no consistent pattern with files being missed out of the zip folder. Occasionally they will all be there, but more often than not some will be missing.

Does anyone know what might be causing this/how it could be fixed? Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程