I am using the Advanced Custom Fields plugin for wordpress to allow a user to upload a CSV file. I then need to get the data from that CSV file. I know I need to use fgetcsv() php function, but I am having trouble.
I can print the object like this:
$file = get_field('location_info');
print_r($file);
which gives me
Array ( [id] => 8 [alt] => [title] => locations => [description] => [mime_type] => text/csv [url] => http://lc.something.com/wp-content/uploads/2016/03/locations.csv )
So how can I get the data out of that csv file using PHP.
I am currently trying:
$file = get_field('location_info');
$filecontents = fgetcsv($file);
But that give me the error “
Warning: fgetcsv() expects parameter 1 to be resource, array given in /var/www/websites/metromont/app/wp-content/themes/metromont/page-contact.php on line 7"
How do i get the ‘resource’ out of this?
Fgetcsv() function expects this resource:
Try to use code snippet below for getting CSV contents:
Output sample data: