Filepaths and Recursion in PHP -
i'm trying recursively iterate through group of dirs contain either files upload or dir check files upload.
so far, i'm getting script go 2 levels deep filesystem, haven't figured out way keep current full filepath in scope function:
function getpathsinfolder($basepath = null) { $fullpath = 'www/doc_upload/test_batch_01/'; if(isset($basepath)): $files = scandir($fullpath . $basepath . '/'); else: $files = scandir($fullpath); endif; $one = array_shift($files); // remove . & .. $two = array_shift($files); foreach($files $file): $type = filetype($fullpath . $file); print $file . ' ' . $type . '<br/>'; if($type == 'dir'): getpathsinfolder($file); elseif(($type == 'file')): //uploaddocsinfolder($file); endif; endforeach; }
so, everytime call getpathsinfolder
have basepath started plus current name of directory i'm scandirring. i'm missing intermediate folders in between. how keep full current filepath in scope?
very simple. if want recursion, need pass whole path parameter when call getpathsinfolder().
scanning large directory tree might more efficient using stack save intermediate paths (which go on heap), rather use more of system stack (it has save path whole frame next level of function call.
Comments
Post a Comment