Access a php file at root directory from my plugin folder

Hi everyone :grinning:,

I have some difficulty requiring a php file from another folder…
I am trying to access a php file in the vendor folder from my plugin folder.

Here is my folder structure

kirby/
panel/
site/
  /plugins/
		/storage/
			storage.php (From here, I require the autoload.php in the vendor folder)
vendor/
	autoload.php

Here is how i’m trying to require the file:

require_once __DIR__ . '/vendor/autoload.php';

I keep getting this error :

require_once(): Failed opening required …. (include_path=‘.:/Applications/MAMP/bin/php/php7.2.1/lib/php:’)

I haven’t changed anything in my .htaccess or php.ini.
Has someone ever see this kind of error?

Thanks you,
Simon

You must relative path to go up the directory tree:

require_once __DIR__ . '/../../../vendor/autoload.php';

You could also require the autoload.php from the index.php file on the root of your project to simplify it. It will be available in your plugin files just fine.

Hi @pedroborges , that worked perfectly.
Thank you :slight_smile:

1 Like