I am creating an Excel reading module in Drupal 8. I want to get the real path of a file for reading it from a path like public://2016-03/Places.xls.
What function should I call for getting the real path of a file?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
@Nisam answer was right but now it's deprecated: function drupal_realpath
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystem::realpath().
So you should use FileSystem::realpath.
$file = File::load($file_id); $uri = $file->getFileUri(); $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')->getViaUri($uri); $file_path = $stream_wrapper_manager->realpath();