我真的不明白为什么我会收到此错误或如何修复它! 传递给each()的变量不是行上的数组或对象 -
while(list($key,$value) = each($_FILES['images']['name']))
完整代码 -
$max_no_img=4; // Maximum number of images value to be set here
$imgs_names = array('CV', 'Research Plan', 'Degree Transcript', 'GRE Scores');
echo "<form method=post action='' enctype='multipart/form-data'>";
echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=left>";
for($i=1; $i<=$max_no_img; $i++){
echo "<tr><td>".$imgs_names[$i-1]."</br</td><td>
<input type=file name='images[]' class='bginput'></td></tr>";
}
echo "<tr><td colspan=2 align=center><input type=submit value='Submit'></td></tr>";
echo "</form> </table>";
while(list($key,$value) = each($_FILES['images']['name']))
{
echo $key;
echo "<br>";
echo $value;
echo "<br>";
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;
有什么想法吗?
答案 0 :(得分:1)
$_FILES['images']['name]
不是数组,$_FILES['images']
是。
所以
while (list($key, $object) = each($_FILES['images']))
{
//use $object['name'] or $object['tmp_name']
}
答案 1 :(得分:0)
$_FILES['images']['name']
不是数组!它是数组中的值。
如果要迭代文件,您应该:
while(list($key,$value) = each($_FILES['images']) {
(...)
}