input type="file"多圖片上傳 原生html傳遞的數組集合


單個的input type="file"表單也是可以實現多圖片上傳的

代碼如下:

    <form action="manypic.php" method="post" enctype="multipart/form-data">
        <input type="file" name="manypic[]" multiple>
        <input type="submit">
    </form>

這里要給file表單加上一個multiple屬性 multiple="multiple"也可以

name的屬性值后面要加上[]這樣就可以了  print_r($_FILES)可得到如下信息:

Array
(
    [manypic] => Array
        (
            [name] => Array
                (
                    [0] => 1.png
                    [1] => bg.jpg
                )

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

            [tmp_name] => Array
                (
                    [0] => D:\xampp\tmp\php8C53.tmp
                    [1] => D:\xampp\tmp\php8C54.tmp
                )

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

            [size] => Array
                (
                    [0] => 44113
                    [1] => 325257
                )
     )
)
這里我上傳的是兩張圖片
另外你也可以提交多個input type="file"上傳域,代碼如下:

    <form action="manypic.php" method="post" enctype="multipart/form-data">
        <input type="file" name="pic1">
        <input type="file" name="pic2">
        <input type="submit">
    </form>
php頁面的print_r的打印結果:
Array
(
 [pic1] => Array  (  [name] => bg.jpg  [type] => image/jpeg  [tmp_name] => D:\xampp\tmp\phpF661.tmp  [error] => 0  [size] => 325257  )   [pic2] => Array  (  [name] => 1.png  [type] => image/png  [tmp_name] => D:\xampp\tmp\phpF671.tmp  [error] => 0  [size] => 44113  ) )

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM