/    Sign up×
Community /Pin to ProfileBookmark

error in Recursive version of glob

Hi all . I got a php script that when i run it i get the following warnnings.
could any one help me fix these warnings .Thanks

[CODE]
Warning: Invalid argument supplied for foreach() in this line…

foreach (glob(“$sDir/*”, GLOB_ONLYDIR) as $sSubDir)
{
$aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
$aFiles = array_merge($aFiles, $aSubFiles);
}

[/CODE]

[CODE]

Warning: sort() expects parameter 1 to be array, boolean given in this line…

/* Get Listing of avatars */
$files = rglob (AVATARS_DIR.AVATARS_DIR_STOCK, ‘*’);
sort ($files, SORT_STRING);
complete code:
[/CODE]

[CODE]
<?php

/**
* Recursive version of glob
*
*
* @return array containing all pattern-matched files.
*
* @param string $sDir Directory to start with.
* @param string $sPattern Pattern to glob for.
* @param int $nFlags Flags sent to glob.
*/
function rglob($sDir, $sPattern, $nFlags = NULL)
{
$sDir = escapeshellcmd($sDir);

// Get the list of all matching files currently in the
// directory.

$aFiles = glob(“$sDir/$sPattern”, $nFlags);

// Then get a list of all directories in this directory, and
// run ourselves on the resulting array. This is the
// recursion step, which will not execute if there are no
// directories.

foreach (glob(“$sDir/*”, GLOB_ONLYDIR) as $sSubDir)
{
$aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
$aFiles = array_merge($aFiles, $aSubFiles);
}

// The array we return contains the files we found, and the
// files all of our children found.

return $aFiles;
}

/* Get Listing of avatars */
$files = rglob (AVATARS_DIR.AVATARS_DIR_STOCK, ‘*’);
sort ($files, SORT_STRING);

[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@CompGeek01Jul 26.2005 — Without everything it's impossible to tell...other than the obvious.

SORT_STRING isn't an array when it's supposed to be.

and

glob() isn't returning a valid array like it's supposed to.
×

Success!

Help @method spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...