1

I started writing an app for nextcloud. For my app to work, I need to be able to pass the complete path of files located in the file directory of the logged in user to a CLI command.

I know that the base path of the file directory is defined in config.php; for example, it is 'var/www/html/nextcloud' or 'var/www/nextcloud'.

I have found a couple of functions that allow me to get the relative path, e.g. \OC\Files\Filesystem::getFileInfo($path) and \OC\Files\Filesystem::getInternalPath($path)

Unfortunately, I couldn't find a function that either directly returns the full path of a file or at least the base path from config.php.

Do any of you have a tip for me?

  • _“or at least the base path from config.php”_ - that appears to store everything in an array called `$CONFIG`, and my guess would be that file simply gets included in a way so that this variable is available in the topmost scope … – misorude Aug 28 '19 at 09:57

1 Answers1

0

Thanks for your help, misorude!

In the meantime I have found a solution:

in Nextcloud there is a class \OC\Config which has the method OC\Config::getValue($key, $default=null) (see https://docs.nextcloud.com/server/latest/developer_manual/api/OC/Config.html)

The difficulty I had with this was that the initialization of a class instance expects the specification of a path, namely the path where the config.php file is located.

This irritated me at first, because it seems you are chasing your own tail here.

Then I tried specifying only the relative path to the Nextcloud installation, and that worked immediately. So to make it short, here's the code you need:

$config = new \OC\Config('config/'); $base_path = $config->getValue('datadirectory')

datadirectory is the key in the array defined in config.php that contains the base directory.

$basepath now contains a path like /var/www/html/nextcloud/data.

I hope this helps someone.

Best regards, Tom