我尝试更改用户文件'在表单中输入名称作为输入名称,从theard Multiple files upload (Array) with CodeIgniter 2.0作为问题的最佳答案,并且它不起作用。
function do_upload()
{
$this->load->library('upload');
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['imageoption']['name']= $files['imageoption']['name'][$i];
$_FILES['imageoption']['type']= $files['imageoption']['type'][$i];
$_FILES['imageoption']['tmp_name']= $files['imageoption']['tmp_name'][$i];
$_FILES['imageoption']['error']= $files['imageoption']['error'][$i];
$_FILES['imageoption']['size']= $files['imageoption']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
}
}
private function set_upload_options()
{
// upload an image options
$config = array();
$config['upload_path'] = './Images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
return $config;
}
以下是HTML表单:
<?php echo $errors;?>
<?php echo form_open_multipart('tryout/guru/do_upload');?>
<div id="Question1">
Image Question
<input type="file" name="imagequestion[]" size="20" />
Image Option
<input type="file" name="imageoption[]" size="20" />
<input type="file" name="imageoption[]" size="20" />
</div>
<div id="Question2">
Image Question
<input type="file" name="imagequestion[]" size="20" />
Image Option
<input type="file" name="imageoption[]" size="20" />
<input type="file" name="imageoption[]" size="20" />
</div>
<br /><br />
<input type="submit" name="submit" value="upload" />
</form>
我想立即为imagequestion
和imageoption
提交不同名称的多次上传。反正有吗?
答案 0 :(得分:0)
您也可以尝试在此处进行更改:
$cpt = count($_FILES['imageoption']['name']);
现在$ i等于$ cpt,因为$ cpt返回0.所以你的for循环在它开始之前结束。
还要确保您的输入有:
"multiple name ='imageoption[]'"
我看到你正在回应$错误......是否显示任何内容?确保将错误传递给您的视图,就像在链接中一样:
$error['error'] = $this->upload->display_errors();
$this->load->view('pages/uploadform', $error);
最好编辑你的第一个答案,而不是发布一个新的答案来真正提出同样的问题。