php - Recursively list files in an archive -


i'm creating method inspect files in upload folder , of these files archive (tar, tar.gz, zip, rar, etc). read these archive files , list files in nested tree format.

for example, have archive file called sandwich.tar.gz, listed below:-

sandwich.tar.gz     lettuce     mayonaise     cheese     bread (directory)         wholemeal 

my code far:-

<?php $archive = new phardata('/upload/directory/sandwich.tar.gz'); foreach($archive $file) {         echo $file . "<br />"; } 

but failed list files inside bread directory. how fix this?

although question rather dated, considering stupidity , uselessness of previous answer, cannot reply.

it seems whatever php non-standard , awkward @ best...

you got right inspect first level. however, objects returned iteration not of same type, calling foreach on them lead failure.

iterating on phardata object gives pharfileinfo ones. there can check file type (checking if directory inherited isdir() method).

from there, need create phardata object on path resource obtained (also inherited) getpathname() (sic, not getpathname() docs!) method. able iterate on it...

full example:

<?php     $archive = new phardata('/upload/directory/sandwich.tar.gz');     foreach($archive $file) {         echo $file;         if($file->isdir()) {             echo ':';             $dir = new phardata($file->getpathname());             foreach($dir $child) {                 echo "<br />$child";             }         }         echo "<br />";     } ?> 

of course, kills easy recursion if have multiple levels in archive. have cook own recursive crawler...


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -