0

In Drupal 6, I am using the following code.

$id = fileowner(file_directory_path());

What is the Drupal 8 equivalent of that code?

1

You can use the following code.

$real_path = \Drupal::service('file_system')->realpath(file_build_uri(''));

On my test site, it returns '/Library/Server/Web/Data/Sites/avpnet/sites/default/files'.

You can also pass a filename to file_build_uri().

$real_path = \Drupal::service('file_system')->realpath(file_build_uri('file.jpeg'));

With this code, I get '/Library/Server/Web/Data/Sites/avpnet/sites/default/files/file.jpeg'.

0

You can use \Drupal\Core\File\FileSystem::realpath() to get the realpath of the file or \Drupal\Core\File\FileSystem::dirname(). As file_directory_path() is deprecated from Drupal 7. For more details please visit at drupal_realpath and drupal_dirname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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