Variable passed to each() is not an array or object
<p>I really don't understand why I'm getting this error or how to fix it!
Variable passed to each() is not an array or object on line-</p>

<pre><code>while(list($key,$value) = each($_FILES['images']['name']))
</code></pre>

<p>Full code-</p>

<pre><code>$max_no_img=4; // Maximum number of images value to be set here
$imgs_names = array('CV', 'Research Plan', 'Degree Transcript', 'GRE Scores');

echo "&lt;form method=post action='' enctype='multipart/form-data'&gt;";
echo "&lt;table border='0' width='400' cellspacing='0' cellpadding='0' align=left&gt;";
for($i=1; $i&lt;=$max_no_img; $i++){
echo "&lt;tr&gt;&lt;td&gt;".$imgs_names[$i-1]."&lt;/br&lt;/td&gt;&lt;td&gt;
&lt;input type=file name='images[]' class='bginput'&gt;&lt;/td&gt;&lt;/tr&gt;";
}

echo "&lt;tr&gt;&lt;td colspan=2 align=center&gt;&lt;input type=submit value='Submit'&gt;&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;/form&gt; &lt;/table&gt;";

while(list($key,$value) = each($_FILES['images']['name']))
{

echo $key;
echo "&lt;br&gt;";
echo $value;
echo "&lt;br&gt;";
if(!empty($value)){   // this will check if any blank field is entered
$filename =rand(1,100000).$value;    // filename stores the value

$filename=str_replace(" ","_",$filename);

$add = "upload/$filename";   // upload directory path is set

copy($_FILES['images']['tmp_name'][$key], $add); 
echo $add;
</code></pre>

<p>Any ideas?</p>
