Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php分段文件以数组形式单独上载_Php_Arrays_File_Input - Fatal编程技术网

php分段文件以数组形式单独上载

php分段文件以数组形式单独上载,php,arrays,file,input,Php,Arrays,File,Input,我已经创建了一个动态注册表,并且与我需要上传文件的一个片段相关 一切都很顺利。除了文件上传 正在打印($文件);尝试上载后会出现以下情况: [0]=> array(5) { ["name"]=> array(2) { [0]=> string(16) "image001 (3).jpg" [1]=> string(16) "image001 (2).jpg" } ["type"]=> array(2)

我已经创建了一个动态注册表,并且与我需要上传文件的一个片段相关

一切都很顺利。除了文件上传

正在打印($文件);尝试上载后会出现以下情况:

    [0]=>
     array(5) {
        ["name"]=>
        array(2) {
  [0]=>
  string(16) "image001 (3).jpg"
  [1]=>
  string(16) "image001 (2).jpg"
}
["type"]=>
array(2) {
  [0]=>
  string(10) "image/jpeg"
  [1]=>
  string(10) "image/jpeg"
}
["tmp_name"]=>
array(2) {
  [0]=>
  string(14) "/tmp/phpdqCWSl"
  [1]=>
  string(14) "/tmp/phpabqqwj"
}
["error"]=>
array(2) {
  [0]=>
  int(0)
  [1]=>
  int(0)
}
["size"]=>
array(2) {
  [0]=>
  int(1288)
  [1]=>
  int(1288)
}
} }

在这里,它将两个上传合并到同一个数组中,而不是使两个子数组的数组大小相同

<td style='display:none;' class=td_register_purchases>
    <input type=text name=registration[][purchase_data] id=purchase_data class=purchase_data>
    <select name='registration[][purchase_type]' id=select_purchase class=purchase_type>
        <option value=1>Accomodation</option>
        <option value=2>Catering</option>
        <option value=3>Tools</option>
        <option value=4>Software/License</option>
        <option value=5>Hardware</option>
    </select>
    <textarea rows=2 cols=50 name='registration[][purchase_comment]' class=purchase_comment placeholder='Comment Area'></textarea>
    <input type=file name='upload_file[]' class='upload-file'> Attachment
</td>


但我可能在某个地方犯了一个错误,这个错误可以解决所有问题。

努力工作。。并找到了一个-不完美的解决方案;-)

$number\u files=sizeof($\u files[“upload\u file”][“name”]);
$fields=4;
$field\u count=0;
$row\U count=0;
如果(!空($\u文件)){
对于($x=0;$x<$number_文件;$x++){
foreach($\作为$reg\数组的文件){
foreach($reg_数组作为$segment=>$value)
{
如果($field\u count==$fields)
{
$temp_文件[$row_count][$segment]=$value[$x];
$field\u count=0;
$row_count++;
}
其他的
{
$field_count++;
$temp_文件[$row_count][$segment]=$value[$x];
}
}//结束foreach
}//结束foreach
}//结束
}//如果结束,则结束
  [0]=>
  array(5) {
    ["name"]=>
    array(1) {
      [0]=>
      string(16) "image001 (3).jpg"
    }
    ["type"]=>
    array(1) {
      [0]=>
      string(10) "image/jpeg"
    }
    ["tmp_name"]=>
    array(1) {
      [0]=>
      string(14) "/tmp/phpdqCWSl"
    }
    ["error"]=>
    array(1) {
      [0]=>
      int(0)
    }
    ["size"]=>
    array(1) {
      [0]=>
      int(1288)
    }
  }

  [1]=>
  array(5) {
    ["name"]=>
    array(1) {
      [0]=>
      string(16) "image001 (2).jpg"
    }
    ["type"]=>
    array(1) {
      [0]=>
      string(10) "image/jpeg"
    }
    ["tmp_name"]=>
    array(1) {
      [0]=>
      string(14) "/tmp/phpabqqwj"
    }
    ["error"]=>
    array(1) {
      [0]=>
      int(0)
    }
    ["size"]=>
    array(1) {
      [0]=>
      int(1288)
    }
  }
}
    $number_files = sizeof($_FILES["upload_file"]["name"]);
    $fields = 4;
    $field_count = 0;
    $row_count = 0;
    if (!empty($_FILES)) {
        for($x = 0; $x < $number_files; $x++) {
            foreach ($_FILES AS $reg_array) {
                foreach ($reg_array AS $segment => $value)
                {
                    if ($field_count == $fields)
                    {
                        $temp_files[$row_count][$segment] = $value[$x];
                        $field_count = 0;
                        $row_count++;
                    }
                    else
                    {
                        $field_count++;
                        $temp_files[$row_count][$segment] = $value[$x];
                    }
                } // end foreach
            } // end foreach
        } // end for
    } // end if