I have a file with an uri and I want to get its raw and relative path.
Uri: public://videos/Test Video.mp4
Path: /sites/default/files/videos/Test Video.mp4
I found already a way to do this:
$file_uri = $file->getFileUri(); // public://videos/Test Video.mp4 $absolute_url = file_create_url($file_uri); // https://www.example.com/sites/default/files/videos/Test%20Video.mp4 $relative_url = file_url_transform_relative($absolute_url); // /sites/default/files/videos/Test%20Video.mp4 $relative_raw_url = rawurldecode($relative_url); // /sites/default/files/videos/Test Video.mp4
Is this the Drupal-way? Or is there a better solution for doing this?