Gautam Golakiya
Gautam Golakiya

Reputation: 452

how to select multiple image in php for mobile website?

I have been trying to upload multiple image in php with this code. I want need is that can select multiple image in php but it can't work in mobile website.

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

sorry for bad english... :)

Upvotes: 1

Views: 2398

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94662

That HTML should work, with a couple of proviso's

  • You have to select all the files in one go i.e. not using more than one click of the browse button. Each new click on the browse button will replace the previous list of files selected.

  • You have to have an enctype="multipart/form-data" on your <form> tag.

This simple example works

<?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>

And produces this output

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
                )
        )
)

Upvotes: 2

Related Questions