Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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_Upload - Fatal编程技术网

Php 从单个文件输入类型转换为同时上载多个文件。新手

Php 从单个文件输入类型转换为同时上载多个文件。新手,php,upload,Php,Upload,我有一个通过表单上传图像的脚本。我想从: <input type="file" name="img_1_upload" class="text"> <input type="file" name="img_2_upload" class="text"> <input type="file" name="img_3_upload" class="text"> <input type="file" name="img_4_upload" class="tex

我有一个通过表单上传图像的脚本。我想从:

<input type="file" name="img_1_upload" class="text">
<input type="file" name="img_2_upload" class="text">
<input type="file" name="img_3_upload" class="text">
<input type="file" name="img_4_upload" class="text">
<input type="file" name="img_5_upload" class="text">
<input type="file" name="img_6_upload" class="text">

要通过以下方式使用多重上传输入类型:

<input name="images[]" id="filesToUpload" type="file" multiple="" />

我的PHP脚本检测输入的图像名称=img_1_upload、img_2_upload、img_3_upload。。。一直到img_6_上传

但是,使用多文件输入类型,我无法将每个文件的名称设置为img_1_upload,。。等等

处理此问题的最佳方法是什么?

您是否尝试过此功能?上传的文件无论如何都是临时文件。您可能需要将它们移动到更合适的位置。移动时,还可以将文件重命名为所需的任何名称

备注:我假设您知道可以使用
$\u files[“images”][“name”][index]
访问文件名,其中index是从0到文件数-1的数组索引


p.S2:还要确保表单具有多个文件的
enctype=“multipart/form data”
属性。

$\u文件数组包含上载文件的信息。上传多个文件时,$\文件的结构如下; 排列


然后,您可以使用一个简单的
foreach()
循环来重命名文件。

您检查过
$\u文件了吗?它在处理多个文件时会更改格式…更改PHP脚本以使用新名称。你面临的问题是什么?
(
    [name] => Array
        (
            [0] => foo.txt
            [1] => bar.txt
        )

    [type] => Array
        (
            [0] => text/plain
            [1] => text/plain
        )

    [tmp_name] => Array
        (
            [0] => /tmp/phpYzdqkD
            [1] => /tmp/phpeEwEWG
        )

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

    [size] => Array
        (
            [0] => 123
            [1] => 456
        )
)