I use ACF file field to import a GPX file, and use a custom php file to :
1) extract GPS datas (distance, elevation, etc)
2) auto-update 6 other ACF fields, using this code added in functions.php, when article is saved.
`require_once(‘gpx_converter/parseGpx.php’);
add_action( ‘save_post’, ‘update_acf_field_value’);
function update_acf_field_value(){
$url = get_field(‘fichier_gpx’, $post->ID)[‘url’];
$gpxStr = file_get_contents($url);
$r = parseGpx($gpxStr);
//print_r (parseGpx($gpxStr));
$lenght = $r->distance;
$lenght2 = ceil($lenght);
$d_plus = $r->d_plus;
$d_plus2 = ceil($d_plus);
$d_moins = $r->d_moins;
$d_moins2 = ceil($d_moins);
$z_min = $r->z_min;
$z_min2 = ceil($z_min);
$z_max = $r->z_max;
$z_max2 = ceil($z_max);
update_field(‘distance’,$lenght2);
update_field(‘denivele_positif’,$d_plus2);
update_field(‘denivele_negatif’,-$d_moins2);
update_field(‘altitude_min’,$z_min2);
update_field(‘altitude_max’,$z_max2);
}
Problem : first time article is saved, ACF file doesn’t seem to be loaded -> datas can’tbe extracted -> fields cannot be updated.
Error message :
Warning: file_get_contents(): Filename cannot be empty
Does anyone know how to solve this problem ?