I have two folders and two files in my wordpress lugin are:
include_once( plugin_dir_path( __FILE__ ) . '/folder1/file1.php');
plugin_dir_path(), can not be use like this with your file and folder configuration.
It returns an error because the file is not found.
Will get the filesystem directory path (with trailing slash) for the plugin
__FILE__ passed in (file2.php in your case).
In your case, in file2.php, it will return :
In the main plugin file, you can add a
defined('MYPLUGIN_DIR') or define('MYPLUGIN_DIR', plugin_dir_path( __FILE__ ));
MYPLUGIN_DIR is available in any file.
include_once( MYPLUGIN_DIR . 'folder1/file1.php');
Will return :
Hope it helps !