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

为什么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
        )

)

正在回答

代码语言

1 回答

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

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

^-^...

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

举报

0/150
提交
取消

为什么print_r后会多出数组

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号