为了账号安全,请及时绑定邮箱和手机立即绑定

为什么print_r后会多出数组


function getFile() {
    $i = 0;
    foreach ( $_FILES as $file ) {
        if (is_string ( $file ['name'] )) {
            $file [$i] = $file;
            $i ++;
        } elseif (is_array ( $file ['name'] )) {
            foreach ( $file['name'] as $key => $val ) {
                $file [$i] ['name'] = $file ['name'] [$key];
                $file [$i] ['type'] = $file ['type'] [$key];
                $file [$i] ['tmp_name'] = $file ['tmp_name'] [$key];
                $file [$i] ['error'] = $file ['error'] [$key];
                $file [$i] ['size'] = $file ['size'] [$key];
                $i ++;
            }
        }
    }
    return  ($file);
}


Array
(
    [name] => Array
        (
            [0] => b.jpeg
            [1] => Lighthouse.jpg
            [2] => Tulips.jpg
            [3] => Lighthouse.jpg
        )

    [type] => Array
        (
            [0] => application/octet-stream
            [1] => image/jpeg
            [2] => image/jpeg
            [3] => image/jpeg
        )

    [tmp_name] => Array
        (
            [0] => D:\wamp\tmp\php6162.tmp
            [1] => D:\wamp\tmp\php6163.tmp
            [2] => D:\wamp\tmp\php6174.tmp
            [3] => D:\wamp\tmp\php6185.tmp
        )

    [error] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
        )

    [size] => Array
        (
            [0] => 5
            [1] => 561276
            [2] => 620888
            [3] => 561276
        )

    [0] => Array
        (
            [name] => b.jpeg
            [type] => application/octet-stream
            [tmp_name] => D:\wamp\tmp\php6162.tmp
            [error] => 0
            [size] => 5
        )

    [1] => Array
        (
            [name] => Lighthouse.jpg
            [type] => image/jpeg
            [tmp_name] => D:\wamp\tmp\php6163.tmp
            [error] => 0
            [size] => 561276
        )

    [2] => Array
        (
            [name] => Tulips.jpg
            [type] => image/jpeg
            [tmp_name] => D:\wamp\tmp\php6174.tmp
            [error] => 0
            [size] => 620888
        )

    [3] => Array
        (
            [name] => Lighthouse.jpg
            [type] => image/jpeg
            [tmp_name] => D:\wamp\tmp\php6185.tmp
            [error] => 0
            [size] => 561276
        )

)

正在回答

2 回答

嗯 就是做成这样二维的索引+关联形式的数组

之后在通过foreach来遍历,将每个文件上传成功

^-^...

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
PHP实现文件上传与下载
  • 参与学习       43735    人
  • 解答问题       328    个

本课程讲解了文件上传的原理和配置,学会两种方式实现文件上传与下载

进入课程

为什么print_r后会多出数组

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信