处理多维 $_FILES 数组 [英] Processing multi-dimensional $_FILES array

查看:53
本文介绍了处理多维 $_FILES 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 $_FILES 数组通过支持表单处理

I have the following $_FILES array past through for processing from a support form

Array
(
    [file] => Array
        (
            [name] => Array
                (
                    [0] => Test.jpg
                    [1] => Test.doc
                    [2] => Test.php
                    [3] => 
                )

            [type] => Array
                (
                    [0] => image/jpeg
                    [1] => image/jpeg
                    [2] => image/jpeg
                    [3] => 
                )

            [tmp_name] => Array
                (
                    [0] => /tmp/phpCO0vSD
                    [1] => /tmp/phpEFpp3Q
                    [2] => /tmp/phpwN4Iwc
                    [3] => 
                )

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

            [size] => Array
                (
                    [0] => 1305787
                    [1] => 339773
                    [2] => 480098
                    [3] => 0
                )

        )

)

我的主要问题是理解处理数组所需的逻辑,检查每个文件是否有效(我已经有一个有效扩展名列表),然后适当地重命名和存储文件.

My main problem is understanding the logic required in order to process the array, check each file is valid (which I already have a list of valid extensions) then rename and store the file appropriately.

Google 和 SO 上的解决方案对于我的简单要求来说都相当复杂.

The solutions on Google and SO are both rather complex for my simple requirements.

推荐答案

以下是遍历数组的方法:

Here is how you would traverse your array:

foreach ($_FILES['file']['name'] as $key => $name) {
    echo $name;
    echo $_FILES['file']['type'][$key];
    echo $_FILES['file']['tmp_name'][$key];
}

有了这个循环,你可以轻松地做你想做的事.

Having this loop you can do what you want easily.

这篇关于处理多维 $_FILES 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆