2

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. Commented Dec 2, 2017 at 19:30

1 Answer 1

2

Use foreach for $_FILES

foreach ($_FILES as $key=>$value)
{
    echo $key; # It's the key that you need
}
Sign up to request clarification or add additional context in comments.

2 Comments

sigh, i'm so dumb i forget that $_FILES is an array. While it seems that CI did not provide any function similar to post(), this fulfill my requirement. Thanks @Yahya
I hoped that in Codeigniter I had something to deal with this. But soluction best is use the global $_FILES variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.