I'm trying to pull some data out of a csv file but I'm stuck because file_exists()
says the file doesn't exist when used with get_template_directory_uri()
.
This is the short code:
function getPeopleNumber() {
$csv = get_template_directory_uri().'/report/report.csv';
$delimiter=',';
if(!file_exists($csv) || !is_readable($csv)) {
return FALSE;
}
$header = NULL;
$data = array();
if (($handle = fopen($csv, 'r')) !== FALSE) {
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
if(!$header) {
$header = $row;
}
else $data[] = array_combine($header, $row);
}
fclose($handle);
}
return $csv;
}
If I echo $csv
there's the complete (and correct) path.
But still the function returns FALSE
. What am I doing wrong?
get_template_directory()
as I suggested in the answer?