Kammy
Kammy

Reputation: 431

How we can read zip file and get information of files or folders contains without unzipping in PHP?

What I actually wanted to do is read zip file and then if it does contain folder then refuse it with some message.

I want user should upload zip file with files only without any directory structure. So I want to read zip file contains and check file structure. I am trying with following code snippet.

$zip = zip_open('/path/to/zipfile'); 
while($zip_entry = zip_read($zip)){
       $filename = zip_entry_name($zip_entry);
       //@todo check whether file or folder.  
}

Upvotes: 3

Views: 1741

Answers (2)

Kammy
Kammy

Reputation: 431

I have sorted out. I am now checking filename as strings wherever I am getting string ending with "/" that am treating as directory else as file.

Upvotes: 3

RolandasR
RolandasR

Reputation: 3047

can't you parse path of $filename? something like $dirName = pathinfo($filename, PATHINFO_DIRNAME)

Upvotes: 1

Related Questions