1
votes

I have an existing zip file. 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. zip is created same like existing zip file, not with updated directory contents. if create the zip with different name or different location it is happening correctly. 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']));
        }
    }
1
Exactly what error are you getting? Have you tried narrowing down the scope of what you are trying to do to determine exactly where the problem is occurring? - Dave
Suppose a zip file test.zip. Now I am deleting test.zip and recreating the same with different files (contents). But I am getting the zip with old files not with new files I have created. - Abhijit

1 Answers

0
votes

I fixed this issue by resetting the zipAdapter path before creating the zip.

$localAdapter = new Filesystem(new LocalAdapter($directoryName));