uploadAsTable()

array uploadAsTable(string variable, [int sheetIndex])

The function uploadAsTable() opens an Excel or CSV file uploaded by the respondent and returns the tabular content as an array.

Return Value

If the file cannot be opened as a table, the function returns null.

Otherwise, an array of all rows is returned, with each entry again being an array with the cells of that row.

[
  ['ID', 'Fruit', 'Quantity'],
  [1, 'Apple, Gala', '72'],
  [2, 'Apple, Braeburn', '19'],
  [3, 'Pear, Conference', '34']
]

Tip: While developing the PHP code, you can display an excerpt of the table by using debug().

$data = uploadAsTable('UP01');
debug($data);
 
if (!$data) {
  // Error message: No file or wrong file format
} elseif (!in_array('ID', $data[0])) {
  // Error message: A column with the heading "ID" is missing
} else {
  // Process the input
}