【问题标题】:change the input name at multiple upload form codeigniter 2.0在多个上传表单codeigniter 2.0中更改输入名称
【发布时间】:2013-11-08 18:01:19
【问题描述】:

我尝试将“用户文件”名称更改为表单中的输入名称,从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>

我想为imagequestionimageoption 一次提交多个不同名称的上传。有没有办法做到这一点?

【问题讨论】:

    标签: php codeigniter codeigniter-2


    【解决方案1】:

    您也可以尝试在此处更改:

    $cpt = count($_FILES['imageoption']['name']);
    

    现在 $i 等于 $cpt 因为 $cpt 返回 0。所以你的 for 循环在它开始之前就结束了。

    还要确保您的输入有:

    "multiple name ='imageoption[]'" 
    

    我看到您正在回显 $errors... 是否显示任何内容?确保您将错误传递给您的视图,就像在链接中一样:

    $error['error'] = $this->upload->display_errors();
    
    $this->load->view('pages/uploadform', $error);
    

    最好编辑您的第一个答案,而不是发布一个新答案来真正提出相同的问题。

    【讨论】:

    • 您可以编辑您的原始评论以发布您的实际表格吗?另外,你确定你有图片的写权限吗?
    猜你喜欢
    • 2015-05-07
    • 2020-03-31
    • 2019-10-28
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 2014-02-04
    • 2015-01-28
    • 2013-02-17
    相关资源
    最近更新 更多