CakePHP 2.X同时上传多个文件

4si2a6ki  于 2022-11-11  发布在  PHP
关注(0)|答案(2)|浏览(162)

在上传多个文件时,您应该如何使用“CakePhpRequest”数组?
我有这个结果

CakeRequest Object
(
[params] => Array
    (
        [plugin] => 
        [controller] => users
        [action] => upload
        [named] => Array
            (
            )

        [pass] => Array
            (
            )

        [form] => Array
            (
                [files] => Array
                    (
                        [name] => Array
                            (
                                [0] => php.exe
                                [1] => php.gif
                                [2] => php.ini
                                [3] => php.ini-development
                                [4] => php.ini-production
                            )

                        [type] => Array
                            (
                                [0] => application/x-msdownload
                                [1] => image/gif
                                [2] => application/octet-stream
                                [3] => application/octet-stream
                                [4] => application/octet-stream
                            )

                        [tmp_name] => Array
                            (
                                [0] => C:\xampp\tmp\php455E.tmp
                                [1] => C:\xampp\tmp\php456E.tmp
                                [2] => C:\xampp\tmp\php456F.tmp
                                [3] => C:\xampp\tmp\php4570.tmp
                                [4] => C:\xampp\tmp\php4571.tmp
                            )

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

                        [size] => Array
                            (
                                [0] => 73728
                                [1] => 2523
                                [2] => 78907
                                [3] => 72908
                                [4] => 72941
                            )

                    )

            )

    )

[...] other data

我是否必须计算上传了多少个文件,然后使用一个数字迭代所有文件?
如果输出是这样的,岂不是更容易?

CakeRequest Object
(
[params] => Array
    (
        [plugin] => 
        [controller] => users
        [action] => upload
        [named] => Array
            (
            )

        [pass] => Array
            (
            )

        [form] => Array
            (
                [files] => Array
                    (
            [0] => Array(
                [name] => php.exe
                [type] => application/x-msdownload
                [tmp_name] => C:\xampp\tmp\php455E.tmp
                [error] => 0
                [size] => 73728
            )
            [1] => Array(
                [name] => php.gif
                [type] => image/gif
                [tmp_name] => C:\xampp\tmp\php456E.tmp
                [error] => 0
                [size] => 2523
            )
            [...] more data

                    )

            )

    )

[...] other data

这样我只需要使用foreach($files as $file)
对不起我的英语不好

70gysomp

70gysomp1#

请将字段名称指定为。

<?php
  echo $this->Form->input('files.', array('type' => 'file', 'multiple')); // dont forgot to put . after the name
?>

您可以在此处获得更多详细信息:https://bakery.cakephp.org/2012/01/31/HTML-5-Multiple-File-Upload-With-Cake.html

58wvjzkj

58wvjzkj2#

在cake 3.x中,在输入名称的末尾使用点会引发空属性错误,根据我的经验,您必须使用[],否则解决方案是相同的,如下所示:http://bakery.cakephp.org/2012/01/31/HTML-5-Multiple-File-Upload-With-Cake.html

相关问题