I need to upload a file (in this case a csv file) and load the contents of it into the following function:
function csv2xml($file, $container = 'data', $rows = 'row')
{
$r = "<{$container}>\n";
$row = 0;
$cols = 0;
$titles = array();
while (($data = fgetcsv($file, 1000, ',')) !== FALSE)
{
if ($row > 0) $r .= "\t<{$rows}>\n";
if (!$cols) $cols = count($data);
for ($i = 0; $i < $cols; $i++)
{
if ($row == 0)
{
$titles[$i] = $data[$i];
continue;
}
$r .= "\t\t<{$titles[$i]}>";
$r .= $data[$i];
$r .= "</{$titles[$i]}>\n";
}
if ($row > 0) $r .= "\t</{$rows}>\n";
$row++;
}
$r .= "</{$container}>";
return $r;
}
This is how im calling the function
csv2xml($_POST['file'], $container = 'wholething', $rows = 'item');
In the form the input box's name is file
I get the following Warning:
fgetcsv() expects parameter 1 to be resource, null given