我需要上传几张图片,我有两个问题,第一个不允许我上传2个或更多的文件,当它是从手机(这里是重要的东西,如果它来自手机,你必须打开相机,如果它是在PC上,它必须显示文件选择窗口,这很好,但对于手机,它只留下一个,到目前为止,我只尝试在Android上使用Crhome)和第二个细节是,第一个元素没有保存,如果它只是一个文件,因为它也不是,它似乎不采取位置,当我放置多个图像时,第一个图像不会保存,其他图像会正确保存。我已经尝试了一段时间,但我看不出有什么问题。附件我的文件结构:\camera
└───上传
└───index.php
└───upload.php
index.php:
<html>
<head>
    <meta charset="UTF-8">
    <title>upload</title>
</head>
<body>
    <form action="upload.php" method="post" multipart="" enctype="multipart/form-data">
        <input type="file" name="img[]" accept="image/*" id="capture" capture="camera" multiple >
        <input type="submit">
    </form>
</body>
</html>和upload.php:
<?php
            echo '<pre>';
            $img = $_FILES['img'];
            if(!empty($img))
            {
                $img_desc = reArrayFiles($img);
                print_r($img_desc);
                foreach($img_desc as $val)
                {
                    $newname = date('YmdHis',time()).mt_rand().'.jpg';
                    move_uploaded_file($val['tmp_name'],'./uploads/'.$newname);
                }
            }
            function reArrayFiles($file)
            {
                $file_ary = array();
                $file_count = count($file['name']);
                $file_key = array_keys($file);
                for($i=0;$i<$file_count;$i++)
                {
                    foreach($file_key as $val)
                    {
                        $file_ary[$i][$val] = $file[$val][$i];
                    }
                }
                return $file_ary;
            }
        ?>发布于 2017-11-23 07:10:47
这对我很有效,Hop这将解决你的第二个问题。
if (isset($_FILES['Gallery']) && is_array($_FILES['Gallery'])) {
                      $errors= array();
                      foreach($_FILES['Gallery']['tmp_name'] as $key => $tmp_name ) {
                        $file_name = $key.$_FILES['Gallery']['name'][$key];
                        $file_size =$_FILES['Gallery']['size'][$key];
                        $file_tmp =$_FILES['Gallery']['tmp_name'][$key];
                        $file_type=$_FILES['Gallery']['type'][$key];
                        if($file_size > 2097152){
                          $errors[]='File size must be less than 2 MB';
                        }
                        if (empty($errors)==true) {
                          if (is_dir('uploads')==false) {
                            mkdir('uploads', 0700);     // Create directory if it does not exist
                          }
                          if (file_exists("uploads/".$file_name)==false) {
                            move_uploaded_file($file_tmp,"uploads/".$file_name);
                            chmod("uploads/".$filename, 0777);
                            $Gallery_Link = "uploads/".$file_name;
                          } else {                                  // rename the file if another one exist
                            $Gallery_Link = "uploads/".time()."_".$file_name;
                            rename($file_tmp,$Gallery_Link) ;
                          }
                        } else {
                          echo $errors;
                        }
                      }
                    }https://stackoverflow.com/questions/47445093
复制相似问题