如何在PHP中为移动网站选择多个图像


how to select multiple image in php for mobile website?

我一直在尝试使用此代码在 php 中上传多个图像。我想要的是可以在php中选择多个图像,但它不能在移动网站中工作。

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

对不起,英语不好... :)

HTML应该可以工作,有几个附带条件

  • 您必须一次性选择所有文件,即不要使用多次单击浏览按钮。每次新单击浏览按钮都将替换之前选择的文件列表。

  • 您必须在<form>标签上有一个enctype="multipart/form-data"

这个简单的例子有效

<?php
if($_SERVER["REQUEST_METHOD"] == 'POST') {
    echo '<pre>POST ARRAY' . print_r($_POST) . '</pre>';
    echo '<pre>FILES ARRAY' . print_r($_FILES) . '</pre>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="img_logo1[]" id="img_logo1" accept="image/*" multiple />
        <button type="submit" name="logout">Go</button>
    </form>
</body>
</html>

并产生此输出

POST ARRAY Array
(
    [logout] => 
)
FILES ARRAY Array
(
    [img_logo1] => Array
        (
            [name] => Array
                (
                    [0] => avatar1.png
                    [1] => avatar100x100.png
                )
            [type] => Array
                (
                    [0] => image/png
                    [1] => image/png
                )
            [tmp_name] => Array
                (
                    [0] => D:'wamp'tmp'phpF7E6.tmp
                    [1] => D:'wamp'tmp'phpF7F7.tmp
                )
            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                )
            [size] => Array
                (
                    [0] => 7666
                    [1] => 4152
                )
        )
)