I’m trying to retrieve folders name from a zip file.
I wrote this simple function :
<?php
class zipadmin{
private $filename ;
private $folder ;
public function __construct($filename,$folder){
$this->zip = new ZipArchive;
$this->file = $filename ;
$this->folder = $folder ;
}
public function listzip(){
if ($this->zip->open($this->file) == TRUE) {
$info = $this->zip->statIndex(0);
$output = str_replace('/','',$info['name']);
return $output;
}
}
}
Problem that if the zip folder contain other files which is not included inside the folders it return all the files names.
I need it to return folders names only and discard any files name.
You can try to check when
$info['crc']equals to zero.Usage example:
Output (array of root-directories only):
In my
test.ziparchive I have few files in root directory of archive and 4 directoriesfolder1,folder2,folder3andfolder4with some files and sub-directories inside them. Running method against archive with no folders returns boolean false.Update:
/.