In Drupal 6, I am using the following code.
$id = fileowner(file_directory_path());
What is the Drupal 8 equivalent of that code?
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'
.
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