I am trying to simple run fopen() in the functions.php, and have also tried it in a test.php wordpress template file.
But it does not work. If I move the test.php file and csv file to a location outside the theme folder then it works first time.
function csv_to_array($filename='', $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename))
return FALSE;
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
echo '<pre>';
var_dump(csv_to_array('csv/nationality-codes.csv'));
echo '</pre>';
This is my folder structure in the theme file...
Any ideas why it does not work?