0

文件上传的 HTML:

 <form enctype="multipart/form-data" action="" method="POST">
                <br/>Upload Featured Image: <input name="imagefiles" type="file" /><br/>
                <br/>Upload Gallery Image 1: <input name="imagefiles" type="file" /><br/>
                <br/>
                <input type="submit" name="submit" value="Add Product" />

</form>

为了处理上传,我这样做:

$imagefiles = $_FILES['imagefiles'];
               foreach ($imagefiles['name'] as $key => $value) ----> [Line 25 in file]
                {


                }

但是,我收到了这个错误:

Warning: Invalid argument supplied for foreach() in /var/www/html/addProductForm.php on line 25 (Edit)
4

1 回答 1

1

您没有使用正确的参数名称。您必须添加[]以使您的输入成为一个数组,否则最后一个元素将覆盖以前具有相同名称的元素..

试试下面的 HTML:

<form enctype="multipart/form-data" action="" method="POST">
   <br/>Upload Featured Image: <input name="imagefiles[]" type="file" /><br/>
   <br/>Upload Gallery Image 1: <input name="imagefiles[]" type="file" /><br/>
   <br/>
   <input type="submit" name="submit" value="Add Product" />
</form>
于 2012-04-23T19:05:20.937 回答