public function parseDataFile()

in api-reference-examples/php/BaseUpload.php [75:118]


  public function parseDataFile($file_name, $options) {
    if (!file_exists($file_name)) {
      throw new Exception(
        "ERROR: Unable to find/read file '$file_name'\n"
      );
    }
    $fh = fopen($file_name, "r");
    $header = null;
    $entries = array();
    $def_privacy_data = $this->getPrivacyDataFromOptions($options);
    $def_description = (isset($options['d']))
      ? $options['d']
      : 'No description provided';
    $def_tag = (isset($options['g'])) ? $options['g'] : '';
    while (($row = fgetcsv($fh)) !== FALSE) {
      if (!count($row) || (count($row) === 1 && !trim($row[0]))) {
        continue; // skip empty rows / queries
      }
      if (strpos($row[0], '#') === 0) {
        continue; // skip lines with comments
      }

      if (!$header) {
        $header = $row;
        continue;
      }

      $post_data = $this->getPostDataFromCSV(array_combine($header, $row));

      // fold in the defaults provided
      if (!isset($post_data['description'])) {
        $post_data['description'] = $def_description;
      }
      if ($def_tag) {
        $post_data['description'] = '['.$def_tag.'] '.$post_data['description'];
      }
      if (!isset($post_data['privacy_type']) && count($def_privacy_data) > 0) {
        $post_data = array_merge($post_data, $def_privacy_data);
      }

      $entries[] = $post_data;
    }
    return $entries;
  }