PHP GENERAL 26 RE PHP ERROR ON ARRAY LOOP THROUGH FOREACH
Date: Tue, 08 Jul 2003 13:05:34 -0400

From: Kurt Milligan (kurt@no-spam)
Subject: Re: [PHP] error on array loop through foreach?

Assuming line 43 is the line "foreach ($filename as $filevalue){",
one guess would be that the variable $filename is not an array;
an array is required. (see php.net/manual/en/control-structures.foreach.php )

If this is the case, you might try to check for an array first;

if(!is_array($filename))
$filename = array($filename);

-Kurt
Micah Montoy wrote:
> It did help and I altered the script a bit. It now reads as:
> > $count = 0;
> //get file size function > function fsize($file) {
> $a = array("B", "KB", "MB");
> $pos = 0;
> $size = filesize($file);
> while ($size >= 1024) {
> $size /= 1024;
> $pos++;
> }
> return round($size,2)." ".$a[$pos];
> }
> //loop through all the chosen file names and input them individually > foreach ($filename as $filevalue){
> > $file_size = !fsize($filevalue);
> > //get specific file name > $parts=explode("\\",$filevalue);
> $file_name=$parts[sizeof($parts)];
> > //get file type extension > $file_type = strrchr($filevalue,'.');
> > mssql_query ("INSERT INTO images (img_location, img_name, img_type,
> img_size, category_id)".
> "VALUES ('{$filevalue}', '{$file_name}', '{$file_type}', '{$file_size}',
> '{$catID}')");
> > $count++;
> //end of loop > }
> > Now I am receiving the error message of:
> > Warning: Invalid argument supplied for foreach() in > c:\inetpub\wwwroot\webpage10\example\u_images\act_load_imgs.php on line 43
> > > Anyone have an idea of what may be causing this?
> > thanks > >