title: Php multiple image uploader with class
body: <p>What am i doing wrong? I cannot send multiple files, only one. I cannot pass an array multiple files into a function.</p>
  <p>Uploading files to the server and saving into sql database - it works.</p>
  <p><strong>form</strong></p>
  <p><code>&lt;input type=&quot;file&quot; name=&quot;product_images[]&quot;</code></p>
  <p><strong>new.php</strong></p>
  <pre><code>$photo_multi = new Photographmultiple();
  
  $id = $database-&gt;insert_id;
  
  $files = 'product_images';
  
  $photo_multi-&gt;upload_file($files, $id);
  </code></pre>
  <p><strong>class Photographmultiple</strong></p>
  <pre><code>public function upload_file($field_name, $id) {
  
      if(isset($_FILES[$field_name])) {
  
          foreach ($_FILES[$field_name]['name'] as $key =&gt; $val) {
  
              $image = ($_FILES[$field_name]['name'][$key]);
              $target_path = $this-&gt;upload_dir . '/' . $image;
              move_uploaded_file($_FILES[$field_name]['tmp_name'][$key], $target_path);
  
              $sql = &quot;INSERT INTO &quot; . self::$table_name . &quot; (&quot;;
              $sql .= &quot;product_id, product_images&quot;;
              $sql .= &quot;) VALUES ('&quot;;
              $sql .= self::$database-&gt;escape_string($id) . &quot;', '&quot;;
              $sql .= self::$database-&gt;escape_string($image) . &quot;')&quot;;
              //echo $sql;
              $result = self::$database-&gt;query($sql);
              return $result;
          }
      }
  
  }
  </code></pre>