$_FILES array and its silly structure [duplicate]

混江龙づ霸主 提交于 2019-12-05 08:43:09

If they all have the same length you can do it like this

for($i = 0; $i < count($_FILES['attachment']['name']); $i++)
{
   echo $_FILES['attachment']['name'][$i] . "<br>";
   echo $_FILES['attachment']['type'][$i] . "<br>";
   echo $_FILES['attachment']['size'][$i] . "<br>";
   echo $_FILES['attachment']['error'][$i] . "<br>";

}

From your code, i suppose your <form> inputs look like this:

<input type="file" name="attachment[]">
<input type="file" name="attachment[]">

If you give unique names to the file fields you should get the $_FILES structure you want:

<input type="file" name="attachment0">
<input type="file" name="attachment1">

results in something like this:

array(2) {
  'attachment0' => array(5) {
    'name'     => string(8) "1528.jpg"
    'type'     => string(0) ""
    'tmp_name' => string(0) ""
    'error'    => int(2)
    'size'     => int(0)
  }
  'attachment1' => array(5) {
    'name'     => string(8) "1529.jpg"
    'type'     => string(0) ""
    'tmp_name' => string(0) ""
    'error'    => int(2)
    'size'     => int(0)
  }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!