多个文件上传到文件夹不起作用

时间:2017-04-08 11:32:15

标签: php html

实际上我想将多个文件上传到我使用过foreach循环的文件夹。在foreach循环中,所有文件都会出现,但是当我尝试移动到文件夹时,它不会上传到文件夹。我怎么解决它。

以下是我的代码,

if(isset($_FILES['additional_images'])){
                  $errors= array();
                  $additionalimages[] = $_FILES['additional_images']['name'];
                  // echo "<pre>";print_r($additionalimages);die;
                  $file_size =$_FILES['additional_images']['size'];
                  $file_tmp =$_FILES['additional_images']['tmp_name'];
                  $file_type=$_FILES['additional_images']['type'];
                  $file_ext=strtolower(end(explode('.',$_FILES['additional_images']['name'])));
                  $extensions= array("jpeg","jpg","png","bmp");

                  if(in_array($file_ext,$extensions)=== false){
                    $errors[]="Invalid extension, please choose a JPEG or PNG file.";
                  }

                  if($file_size > 10485760){
                    $errors[]='File size must be less than 10MB';
                  }
                  $file_ary = array();
                $file_count = count($additionalimages);
                $file_keys = array_keys($additionalimages);

                for ($i=0; $i<$file_count; $i++) {
                    foreach ($file_keys as $key) {
                        $file_ary[$i][$key] = $additionalimages[$key][$i];
                        $images = implode(',',$file_ary);
                        $true = move_uploaded_file($file_tmp,'images/additionalimages/'.$images);
                        if($true){
                            echo "success";die;
                        }
                        else
                        {
                            echo "fail";die;
                        }
                    }
                }

0 个答案:

没有答案