0

Usually, to check for a directory, you would use $zipArchive->locateName( "dirName" ); but while the zipfile is being created, this does not work. Is there a way to check the zip file during creation for directories?

Does not work:

$zip = new ZipArchive();

$zip->open( $path, ZIPARCHIVE::CREATE );

//Returns false even if already created
if ( $this->locateName( $directory ) === false ) ...

$this->statName(...) also returns false;

Don Rhummy
  • 24,730
  • 42
  • 175
  • 330

1 Answers1

3

Had the same problem and found that adding a slash to the end of the directory name worked.

$zip->addEmptyDir("directoryName");
$zip->locateName("directoryName");  // Returns false
$zip->locateName("directoryName/"); // Returns the location as expected
Tonxey
  • 51
  • 3
  • Thanks, but this only works when you manually add the empty directory manually. So this does not work when you add a file in a diretory without creating the directory first. – Ruben Jun 30 '21 at 15:11