...

View Full Version : Resolved Need assistance on this error..



djdubuque
03-25-2010, 03:35 PM
Error

Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/tms/adminpanel/systeminfo.php on line 150Code at line 150


}
echo "</table>
";
function filesize_r($path)
{
if(!file_exists($path))
return 0;
if(is_file($path))
return filesize($path);
$ret = 0;
foreach(glob($path."/*") as $fn)
$ret += filesize_r($fn);
return $ret;
}

tomws
03-25-2010, 04:29 PM
That suggests you're not getting the expected result (Array) from glob(). Test the return value before using it in a foreach. According to the documentation (http://php.net/glob), possible return values are "an array containing the matched files/directories, an empty array if no file matched or FALSE on error."

$arr = glob($path."/*");
if (is_array($arr) && !empty($arr))
{
// do foreach and return
}

Fou-Lu
03-25-2010, 04:31 PM
Probably the recurse thats causing that. Fairly sure that glob returns its items without the filepath, so you'll need to recall filesize_r with $path . '/' . $fn as its argument.
Another option is to look at using the RecursiveDirectoryIterator/RecursiveIteratorIterator classes if available for use.

djdubuque
03-25-2010, 05:09 PM
That suggests you're not getting the expected result (Array) from glob(). Test the return value before using it in a foreach. According to the documentation (http://php.net/glob), possible return values are "an array containing the matched files/directories, an empty array if no file matched or FALSE on error."

$arr = glob($path."/*");
if (is_array($arr) && !empty($arr))
{
// do foreach and return
}


OK, this corrected the error, but the result is "0"

Site Folder Size 0 Bytes

MattF
03-25-2010, 05:26 PM
$ret += filesize_r($fn);


Should be:



$ret += filesize($fn);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum