如何从Codeigniter中的输入文件中获取字段名称

时间:2017-12-02 10:06:40

标签: php arrays codeigniter

我需要在Codeigniter中获取输入类型文件的源字段名称。我有多个输入文件,其名称基于"upload_file_12, upload_file_13, upload_file_(n)"

等ID生成

我知道输入文件正在使用$_FILES,而不是$_POST,以及

中无法使用的原因
$this->input->post(); # (which have input field name as array key)

但如果我使用$_FILES,那么我需要对名称进行硬编码,或者至少是前缀

$_FILES['upload_file_'.$i]

我不介意使用,但是有没有办法让字段名称像使用$this->input->post()一样?

编辑:

例如:

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

我需要获取name='upload_file_12'部分,而$_POST不属于$_FILES,而是[{"id":"65001585.8c9564","type":"http in","z":"4737d790.fefe58","name":"badger","url":"/Badger","method":"get","upload":false,"swaggerDoc":"","x":76,"y":72,"wires":[["980800c8.6789f","ab39736b.ffbfd"]]},{"id":"980800c8.6789f","type":"http request","z":"4737d790.fefe58","name":"URBAN DICTIONARY","method":"GET","ret":"txt","url":"https://urban.now.sh/random/Honey Badger","tls":"","x":269,"y":106,"wires":[["c0ff5132.822508"]]},{"id":"ab39736b.ffbfd","type":"http response","z":"4737d790.fefe58","name":"http response","x":1016.5551147460938,"y":75.22221374511719,"wires":[]},{"id":"e98c98a8.0a9a28","type":"template","z":"4737d790.fefe58","name":"Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<HTML>\n\n\t<HEAD>\n\t\t<TITLE> [ H O N E Y B A D G E R ] </TITLE>\n\t\t<META HTTP-EQUIV=\"refresh\" CONTENT=\"300\">\n<style>\np.minortext\n{\n font-family: \"Arimo\";\n color:#A9A9A9\n}\np.majortext\n{\n font-family: \"Impact\";\n color:black\n size:20\n}\n\n</style>\n</head>\n\n\t<BODY>\n\t <CENTER>\n\t <Table Width = \"100%\" Bgcolor=\"#A9A9A9\"><TR><TD ALIGN = \"CENTER\">\n\t <a class=\"weatherwidget-io\" href=\"https://forecast7.com/en/n34d93138d60/adelaide/\" data-font=\"Roboto Slab\" data-mode=\"Current\" data-days=\"3\" data-shadow=\"#000000\" data-accent=\"#000000\" data-textColor=\"#ffffff\" data-highColor=\"#ffffff\" data-lowColor=\"#ffffff\" data-sunColor=\"#ffffff\" data-moonColor=\"#ffffff\" data-cloudColor=\"#ffffff\" data-cloudFill=\"#ffffff\" data-rainColor=\"#ffffff\" data-snowColor=\"#ffffff\" >Adelaide, South Australia, Australia</a>\n<script>\n!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"https://weatherwidget.io/js/widget.min.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"weatherwidget-io-js\");\n</script>\n</td><td align = \"center\">\n\n\n</td>\n\n\n\n</TD><TD ALIGN = \"RIGHT\"><IMG SRC=\"LogIn.PNG\"> </TD></TR></Table>\n\t <Table Width = \"500\" Height = \"620\" Border = \"0\">\n\t <TR Width = \"500\" Height = \"320\">\n\t <TD Width = \"500\" Height = \"320\" VALIGN = \"CENTER\">\n\t\t<CENTER>\n\t\t\t <FONT SIZE = \"20\">\n <p class=\"majortext\">\n <IMG SRC=\"HoneyBadger.PNG \" ALT=\"HoneyBadger\"><BR>\n\t\t\t\t <B>H O N E Y B A D G E R</B>\n\t\t\t </P>\n\t\t\t </FONT>\n\t\t\t </TD>\n\t\t\t </TR>\n\t\t\t \t <TR Width = \"500\" Height = \"300\">\n\t <TD Width = \"500\" Height = \"300\" VALIGN = \"TOP\">\n\t\t\t<CENTER>\n\t\t\n\t\t\t<p class=\"minortext\">\n\t\t\t \t\t\t <FONT SIZE = \"5\">\n\t\t\t {{{payload}}}\n </P>\n\t\t</CENTER>\n\t\t </TD>\n\t\t </TR>\n\t\t </TABLE>\n\t\t</CENTER>\n\t</BODY>\n</HTML>\t\t\t \n\n","output":"str","x":830.0000610351562,"y":108.55557250976562,"wires":[["ad7d02ac.52565","ab39736b.ffbfd"]]},{"id":"ad7d02ac.52565","type":"debug","z":"4737d790.fefe58","name":"","active":true,"console":"true","complete":"payload","x":1013.3883666992188,"y":153.77764892578125,"wires":[]},{"id":"c0ff5132.822508","type":"function","z":"4737d790.fefe58","name":"test","func":"var parts = msg.payload.split(\"definition\");\nvar message1 = { payload: parts[0] };\nvar message2 = { payload: parts[1] };\nvar msg2parts = message2.payload.split(\"URL\");\nvar msgsparts1 = {payload: msg2parts[0]};\nvar msgsparts2 = {payload: msg2parts[1]};\n\n\nreturn msgsparts1;\n","outputs":"1","noerr":0,"x":446.75921630859375,"y":106.75926971435547,"wires":[["e132da2c.78b1a8"]]},{"id":"e132da2c.78b1a8","type":"change","z":"4737d790.fefe58","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"\"\"","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\\n","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"n\\","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":":","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\"\"\"","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":".\",\"\"","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\\","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\"","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"example","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":628.8887939453125,"y":107.99996948242188,"wires":[["e98c98a8.0a9a28"]]}]

2 个答案:

答案 0 :(得分:1)

DataFrame用于MultiIndex

foreach

答案 1 :(得分:0)

只要您希望将数组键作为变量并将数组值作为变量值,请使用extract函数。

$post = $this->input->post();
extract($post);  // use array key as variable

例如: -

$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
echo "Value of a is :- ".$a; // It displays 'Cat'