1
votes

I need to get source field name for input type file in Codeigniter. I have multiple input file with names generated based on id like "upload_file_12, upload_file_13, upload_file_(n)"

I know input file is using $_FILES, not $_POST, and that's why they not available in

$this->input->post(); # (which have input field name as array key)

But if i use $_FILES then I need to hard-code the name, or at least the prefix

$_FILES['upload_file_'.$i]

which i don't mind using, but is there any way to get the field name like using $this->input->post()?

Edit:

For example :

<input type='file' name='upload_file_12'>

I need to get the name='upload_file_12' part, which not in part of $_POST, but $_FILES.

1
I don't believe ci had that. Only for get and post. And tbh the only thing it does is access the post array and check if it's set. The way you are doing it is fine. That being said ci does have an uploader class where you just specify the name of the field, but again that's not much more different than what you are doing. - Alex

1 Answers

1
votes

Use foreach for $_FILES

foreach ($_FILES as $key=>$value)
{
    echo $key; # It's the key that you need
}