2

i've problem with my code here.

The case is, i have multiple input file form, i need to get name of current array (which contain database id) and upload the file from it.

Here's in my views

foreach($result2 as $result3)
{
   print "
   <tr>
       <td><input type=file name=baddismantling[".$result3['iddeployment']."] size=20></td>
   </tr>
   ";
}

so, there'll be various of upload form and name too, but it always unique.

and after user click submit button, that form will call function in my controller, and here's the function that handled it

private function _ready_to_start($sessiondata)
{
    if($post['doSubmitDismantlingAction'] == 'uploadbad')
    {
        while ($fruit_name = current($_FILES['baddismantling']['name']))
        {
            if($fruit_name != false)
        {
                //GET ID FROM DEPLOYMENT DB
            $deploymentid = key($_FILES['baddismantling']['name']);
                $file = "baddismantling[$deploymentid]";
            if(!$this->upload->do_upload($file))
                {
                    $check3[] = $this->upload->display_errors()." target: ".$file;
                }
            $check2 = $this->upload->data();
        }
            next($_FILES['baddismantling']['name']);
        }
        //SHOW RESULT WHILE UPLOADING
        print implode($check3);
    }
}

as you see,i've successful with getting the

$deploymentid = 1

as i wish...but, browser give me :

You did not select a file to upload. target: baddismantling[1]

anyone can give me suggestion about that problem?or there's something wrong with my code?

as note :

there's no problem with configuration $this->upload-> because i've successfull with a single upload form only

1
  • check the file_size. "if POST size exceeds server limit then $_POST and $_FILES arrays become empty."
    – plain jane
    Commented Sep 19, 2013 at 5:10

1 Answer 1

1

thanks for your time with my question, and i've "luckily" got my own solving from question above with this code :

$check3 = array();
$count = 0;
$check = ($_FILES == true ? count($_FILES['baddismantling']['name']) : (0));
while ($fruit_name = ($check == true && $check > 0 ? current($_FILES['baddismantling']['name']) : (false)) || $count <= $check){
$count++;
if($fruit_name == true && key($_FILES['baddismantling']['name']) == true)
{
    $iddeployment = key($_FILES['baddismantling']['name']);
    /*THIS PART WAS HELPING ME*/if($_FILES['baddismantling']['name'][$iddeployment] == true)
    {
    $_FILES['userfile']['name']     = $_FILES['baddismantling']['name'][$iddeployment];
    $_FILES['userfile']['type']     = $_FILES['baddismantling']['type'][$iddeployment];
    $_FILES['userfile']['tmp_name'] = $_FILES['baddismantling']['tmp_name'][$iddeployment];
    $_FILES['userfile']['error']    = $_FILES['baddismantling']['error'][$iddeployment];
    $_FILES['userfile']['size']     = $_FILES['baddismantling']['size'][$iddeployment];
    if (!$this->upload->do_upload())
    {
        $check3[] = $this->upload->display_errors();
    }
    else
    {
        $uploaddata = $this->upload->data();
        $result['badfilename'] = $uploaddata['full_path'];
        $result['id'] = $iddeployment;
        $sql = $this->sql->updatedismantlingBAD($result);
    }
}
}
next($_FILES['baddismantling']['name']);}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.