x1a4
March 28th, 2011, 10:53 PM
Hi,
I've a function that worked for years and is now suddenly throwing an 'Invalid argument supplied for foreach()' warning. Could someone please have a look and tell me what the problem is and how to fix it? Thank you.
function recurse($path,$walldirs=array()) //{{{
{
foreach(glob($path."/*",GLOB_ONLYDIR) as $d) //{{{
{
$GLOBALS['walldirs'][]=$d;
recurse($d,$walldirs);
} //}}}
} //}}}
$walldirs=array();
recurse($_SERVER[DOCUMENT_ROOT]."/wallpapers");
$wallcount=0;
foreach($walldirs as $dd) //{{{
{
$wallcount+=count(glob($dd."/*.jpg"));
} //}}}
$walldirs=array();
The whole thing is supposed to recursively count JPEGs. The function in question is supposed to get me all the directories and subdirectories. The foreach() in question is the one inside the recurse() function.
I've a function that worked for years and is now suddenly throwing an 'Invalid argument supplied for foreach()' warning. Could someone please have a look and tell me what the problem is and how to fix it? Thank you.
function recurse($path,$walldirs=array()) //{{{
{
foreach(glob($path."/*",GLOB_ONLYDIR) as $d) //{{{
{
$GLOBALS['walldirs'][]=$d;
recurse($d,$walldirs);
} //}}}
} //}}}
$walldirs=array();
recurse($_SERVER[DOCUMENT_ROOT]."/wallpapers");
$wallcount=0;
foreach($walldirs as $dd) //{{{
{
$wallcount+=count(glob($dd."/*.jpg"));
} //}}}
$walldirs=array();
The whole thing is supposed to recursively count JPEGs. The function in question is supposed to get me all the directories and subdirectories. The foreach() in question is the one inside the recurse() function.