3

I just trying to get the real path of my private filesystem but I just obtain an empty string if I use:

\Drupal::service('file_system')->realpath("private://");

There one user in Get the public path directory that says that this is the correct way, but this is not working for me.

My private filesystem is configured as:

$settings['file_private_path'] = '/User/adriancid/private-drupal-folder';

enter image description here

If I use file_default_scheme() I see:

private

6
  • Does it work with temporary:// or public://? Could be that you have not configured the private path in settings.php.
    – 4uk4
    May 12, 2017 at 20:00
  • @4k4 It works for public, and I have configured my private filysystem. May 12, 2017 at 20:01
  • @4k4 This code: \Drupal::service('file_system')->realpath("private://"); works for you? May 12, 2017 at 20:05
  • Yes, it works when a private path is configured and returns FALSE on a site with no path configured. I see in the edit, you have an absolute path outside of the web root, is the path accessible by the web server?
    – 4uk4
    May 12, 2017 at 20:12
  • @4k4 no, is not accesible by the web server. May 12, 2017 at 20:24

1 Answer 1

5

The problem is solved.

I had a problem with the path, so the correct path is

$settings['file_private_path'] = '/Users/adriancid/private-drupal-folder';

And I give permissions to write in the folder to the webserver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.