title: Submit xml to GSA with PHP / foreach loop
body: <p>Trying to submit to GSA (google search applicance). Works fine for 1 xml file. But im trying to loop through all files in a directory and submit to the gsa with a loop but cannot get it working.</p>
  
  <pre><code>&lt;?php
  
  $target_url = 'http://1.1.1.1:19900/xmlfeed';
  
  $header = array('Content-Type: multipart/form-data');
  
  $directory = 'xml';
  
  if (! is_dir($directory)) {
      exit('Invalid diretory path');
  }
  
  $files = array();
  
  foreach (scandir($directory) as $file) {
      if ('.' === $file) continue;
      if ('..' === $file) continue;
  
  }
  
  //print $file;
  
  
  
  $fields = array(
  'feedtype'=&gt;'incremental',
  'datasource'=&gt;'testing',
  'data'=&gt;file_get_contents(realpath($file))
  //'data'=&gt;file_get_contents(realpath('test.xml')) //works fine
  
  );
  
  
  
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  curl_setopt($ch, CURLOPT_TIMEOUT,120);
  curl_setopt($ch, CURLOPT_URL,$target_url);
  curl_setopt($ch, CURLOPT_POST,1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  
  $return = curl_exec($ch);
  
  if (curl_errno($ch)) {
      $msg = curl_error($ch);
  }
  
  curl_close ($ch);
  
  
  
  echo $return;
  </code></pre>
  
  <p>?></p>
  
  <p>Tried adding a foreach loop but that gives me an error that the file is empty.</p>