动态POST php变量

Attempting to POST a certain number of variables based on the number of images in a folder. The variables are based on numbers found in fields with input name "Pano__000nheading" when n is the number in the current loop. I believe i have the code working properly on the page which is getting the values just need help if you see any flaws here is my code:

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 $id = substr( $url, strrpos( $url, '&' )+1 );
    $dirname = "../wp-content/themes/Explorable/".$id."/"; 
  $images = glob($dirname."*.jpg");
// Open a known directory, and proceed to read its contents  
foreach($images as $image) {
 $imageNameLong = substr($image, -14);
$imageName = substr($imageNameLong,0 , -4);

 if ( isset( $_POST[$imageName.'links'] ) )
            update_post_meta( $post_id, '_'.$imageName.'links', sanitize_text_field( $_POST[$imageName.'links'] ) );
        else
            delete_post_meta( $post_id, '_'.$imageName.'links' ); 

    if ( isset( $_POST[$imageName.'heading'] ) )
            update_post_meta( $post_id, '_'.$imageName.'heading', sanitize_text_field( $_POST[$imageName.'heading'] ) );
        else
            delete_post_meta( $post_id, '_'.$imageName.'heading' ); 
};