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
Post a Comment