title: PHP multiple image inputs
body: <p>I made code which every time user add image append another input for image.</p>
  
  <p>It looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/xgv3s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xgv3s.png" alt="enter image description here"></a></p>
  
  <p>And this is code for that:</p>
  
  <pre><code>&lt;form action="" method="POST" enctype="multipart/form-data"&gt;
      &lt;ul class="add_img_ul"&gt;
          &lt;li class="subimg"&gt;&lt;input type="file" class="file" name="images[]" required multiple/&gt;&lt;img class="add" src="icons/add.jpg" width="80px" height="80px"/&gt;&lt;/li&gt;
      &lt;/ul&gt;                       
  &lt;script&gt;
      var inputLocalFont = document.querySelector(".file");
      inputLocalFont.addEventListener("change",previewImages,false);
  
      function previewImages(){
          var fileList = this.files;
  
          var anyWindow = window.URL || window.webkitURL;
  
          for(var i = 0; i &lt; fileList.length; i++){
              var objectUrl = anyWindow.createObjectURL(fileList[i]);
              $('.add_img_ul').append('&lt;li class="subimg"&gt;&lt;input type="file" class="file" name="images[]"/&gt;&lt;img class="add_img" src="' + objectUrl + '" width="80px" height="80px"/&gt;&lt;/li&gt;');
              window.URL.revokeObjectURL(fileList[i]);
              }   
      }           
  
  
  &lt;/script&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And my php code:</p>
  
  <pre><code>if(isset($_FILES['images'])){
      $number_of_file_fields = 0;
      $number_of_uploaded_files = 0;
      $number_of_moved_files = 0;
      $uploaded_files = array();
      $upload_directory = 'product_images';
  
      for($i = 0; $i &lt; count($_FILES['images']['name']); $i++){
          $number_of_file_fields++;
          if($_FILES['images']['name'][$i] != ''){
              $number_of_uploaded_files++;
              $uploaded_files[] = $_FILES['images']['name'][$i];
              if(move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])){
                  $number_of_moved_files++;
              }
          }
      }
  
      $name = implode(',', $uploaded_files);
      echo $name;
  }
  </code></pre>
  
  <p>Record of image path is stored into <code>$name</code></p>
  
  <p>When I run my code in <code>$name</code> is only one value, but when I add <code>required multiple</code> on one input then is good.</p>
  
  <p>How can I store values from different inputs, but with same name into <code>$name</code>?</p>
  
  <p>Thanks</p>