How can we read a zip file and get information about files or folders without unpacking in PHP?

What I really wanted to do was read the zip file, and then if it contains a folder, cancel it with some message.

I want the user to upload a zip file with files only without any directory structure. So I want to read the zip file and check the file structure. I am trying to make the 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.  
}
+3
source share
2 answers

I figured it out. I am now checking the file name as a string, where I get a string ending in "/", which is treated as an else directory as a file.

+3
source

Unable to parse the path to $ filename? sort of$dirName = pathinfo($filename, PATHINFO_DIRNAME)

+1
source

Source: https://habr.com/ru/post/1766517/


All Articles