表单未在 codeigniter 中正确提交

Form is not submitting properly in codeigniter

我有一个表格,假设 post 信息和上传图片,当我 post 信息时,表格正在做它应该做的事情,但是当我浏览照片时,它 post 注意到,既不是信息也不是文件,任何人都可以帮助我为什么这样做? 实际上,我在表单中有 7 个文件字段,其中一个可以工作,但多个不能工作。

<?php $attributes = array("name" => "project_add");
echo form_open_multipart("project/add", $attributes);?>
<?php echo $this->session->flashdata('msg'); ?>
Project Name <span>*</span><br/>
<input class="form-control" name="name" id="name" type="text"value="<?php echo set_value('name'); ?>" /><br/>
<input class="form-control" name="f_lcpd" id="f_lcpd" type="checkbox" />     <label for ="">Painted Desert</label>`
Invoice <input class="form-control" name="userfile[]" id="" type="file"  />
image 1<input class="form-control" name="userfile[]" id="" type="file"  />
Image 2<input class="form-control" name="userfile[]" id="" type="file"  />
<input type="submit" value="Save" />
<?php echo form_close(); ?>

控制器功能

public function add()
{
print_r($_POST);
print_r($_FILES);
}

向服务器提交文件时应使用enctype="multipart/form-data"(形成)。在服务器端,您可以使用 $_FILES supergloal 访问这些文件,您可以使用 $_POST 访问标准 POST 数据(仅当 method="POST"

如果您想提交多个文件,您的代码应如下所示:

<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />

然后,在服务器端(如果您没有使用任何助手):

foreach($_FILES['userfile']['tmp_name'] as $key => $tmp_name)
     // process image upload, e.g. if you want the size: $_FILES['userfile']['size'][$key]
}

您可以将上述解决方案与 CodeIgniter 中的 do_upload 方法结合使用。