Hi …
I am using the Options page to allow the user to upload a csv file that runs chart.
Everything works except the file no longer overwrites the current data file instead it creates a copy as gas-elec-daily-1.csv instead of overwriting gas-elec-daily.csv. I am sure this was working but it seems to have stopped and I cannot work out why – so any pointers gratefully received.
// Gas & Elec Daily
add_filter('acf/upload_prefilter/name=gas_elec_data', 'field_name_upload_prefilter');
function field_name_upload_prefilter($errors) {
// in this filter we add a WP filter that alters the upload path
add_filter('upload_dir', 'field_name_upload_dir');
add_filter('wp_handle_upload_prefilter', 'rename_current_daily_upload', 11, 1);
return $errors;
}
function rename_current_daily_upload( $file ){
$file['name'] = 'gas-elec-daily.csv';
return $file;
}
// second filter
function field_name_upload_dir($uploads) {
// here is where we alter the path
$uploads['path'] = $uploads['basedir'].'/data';
$uploads['url'] = $uploads['baseurl'].'/data';
$uploads['subdir'] = '';
return $uploads;
}
** Ignore this – I have asked a similar question a few months ago **
Alternatively – is there a way I can get the file field form within the Java file – currently using – field name ‘gas_elec_data’
// Set up data source
chart.dataSource.url = “https://weareinteb.co.uk/wp-content/uploads/data/gas-elec-monthly.csv”;