Don Rhummy
Don Rhummy

Reputation: 25870

How check if directory already added to ZipArchive during creation?

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;

Upvotes: 0

Views: 1853

Answers (1)

Tonxey
Tonxey

Reputation: 51

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

Upvotes: 3

Related Questions