-2

I try to change the 'userfile' name as input name in form, from the theard Multiple files upload (Array) with CodeIgniter 2.0 as the best answers for the question, and it doesn't work.

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;
}

Here is the HTML form:

<?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>

I want to make multiple upload with different name for the imagequestion and imageoption at once submit. Is there anyway to do that?

Community
  • 1
  • 1
nosada29
  • 1
  • 1

1 Answers1

0

You could try changing it here too:

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

Right now $i is equal to $cpt since $cpt is returning 0. So your for loop ends before it begins.

Also make sure that your input has:

"multiple name ='imageoption[]'" 

I see that you are echoing $errors... is that displaying anything at all? Make sure you are passing your errors to your view just like in the link:

$error['error'] = $this->upload->display_errors();

$this->load->view('pages/uploadform', $error);

It's always best to edit your first answer rather than posting a new answer to really ask the same question.

Spatial Pariah
  • 351
  • 4
  • 17