我试图递归迭代通过一组包含要上传的文件或另一个目录以检查要上载的文件的目录。PHP中的文件路径和递归
到目前为止,我得到我的脚本去2层深入到文件系统,但我还没有想出一个办法,以保持我目前的完整文件路径范围为我的功能:
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); // to remove . & ..
$two = array_shift($files);
foreach($files as $file):
$type = filetype($fullpath . $file);
print $file . ' is a ' . $type . '<br/>';
if($type == 'dir'):
getPathsinFolder($file);
elseif(($type == 'file')):
//uploadDocsinFolder($file);
endif;
endforeach;
}
所以,每次我打电话getPathsinFolder
我有我开始的基本路径加上我正在scandirring目录的当前名称。但我错过了中间的中间文件夹。如何保持完整的当前文件路径在范围内?
您可以使用[ RecursiveDirectoryIterator](http://www.php.net/manual/en/recursivedirectoryiterator.construct.php)class – 2013-05-03 01:50:06