I have this PHP code:
$rootpath = '../admin/';
$inner = new RecursiveDirectoryIterator($rootpath);
$fileinfos = new RecursiveIteratorIterator($inner);
foreach ($fileinfos as $pathname => $fileinfo)
{
$pathname2 = substr($pathname,2);
$sql = "SELECT * from admin_permissions where page_name = '$pathname2'";
$rs = mysql_query($sql,$conn);
if (mysql_num_rows($rs) == 0)
{
if (!$fileinfo->isFile()) continue;
$sql2 = "INSERT into admin_permissions (page_name) values ('$pathname2')";
$rs2 = mysql_query($sql2,$conn);
echo "$pathname<br>";
}
}
This displays my directory structure and inserts directories and file names into the database (deleting the first two characters ..
).
Since RecursiveDirectoryIterator
iterates over all files in all directories, how can I exclude whole directories, including all files inside them?
source
share