How about just define a constant that stores the plugin’s root path?
Define path constant
For calling numerous files, it is sometimes convenient to define a
constant:define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); include( MY_PLUGIN_PATH . 'includes/admin-page.php'); include( MY_PLUGIN_PATH . 'includes/classes.php'); // etc.
— See https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-491
So in your main plugin file:
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
And then in folder/otherfolder/req-file-to-here.php
, do:
require MY_PLUGIN_PATH . 'req-file-from-here.php';
Alternatively, you could define just the path to the main plugin file:
define( 'MY_PLUGIN_FILE', __FILE__ );
And then in folder/otherfolder/req-file-to-here.php
, do:
require plugin_dir_path( MY_PLUGIN_FILE ) . 'req-file-from-here.php';