简体   繁体   English

使用flysystem-ziparchive创建zip时遇到的问题

[英]Facing issues while creating a zip using flysystem-ziparchive

I have an existing zip file. 我有一个现有的zip文件。 I am facing an error while trying to do the below using flysystem-ziparchive unzipped to a directory deleted the zip file deleted some unnecessary files in the directory create a zip with same name and same location from the directory. 我在尝试使用flysystem-ziparchive执行以下操作时遇到错误,将其解压缩到目录中删除了zip文件,删除了目录中一些不必要的文件,从目录中创建了一个具有相同名称和相同位置的zip。 zip is created same like existing zip file, not with updated directory contents. zip的创建方式与现有zip文件相同,但没有更新的目录内容。 if create the zip with different name or different location it is happening correctly. 如果使用不同的名称或不同的位置创建该zip,则说明该情况正确。 sample coding: 样本编码:

$zipAdapter = new Filesystem(new ZipArchiveAdapter($zipFile));
$localAdapter = new Filesystem(new LocalAdapter($directoryName));

//unzip to a folder
unZip($directoryName, $zipFile);

//Deleting zip file
unlink($zipFile);

$zipAdapter->createZip($directoryName);

//method to create zip
public function createZip($directory)
    {
        //get list of files from source
        $files = $localAdapter->listContents();

        //Create zip
        foreach ($files as $file)
        {
            $zipAdapter->putStream($file['basename'], $this->local->readStream($file['basename']));
        }
    }

I fixed this issue by resetting the zipAdapter path before creating the zip. 我通过在创建zip之前重置zipAdapter路径来解决此问题。

$localAdapter = new Filesystem(new LocalAdapter($directoryName)); $ localAdapter =新文件系统(new LocalAdapter($ directoryName));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM