Skip to content

Instantly share code, notes, and snippets.

@illepic
Last active August 23, 2023 09:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illepic/fa451e49c5c43b4a1742333f109dbfcd to your computer and use it in GitHub Desktop.
Save illepic/fa451e49c5c43b4a1742333f109dbfcd to your computer and use it in GitHub Desktop.
Get relative path for fid in Drupal 8
<?php
use Drupal\file\Entity\File;
// public://images/blah.jpg
$drupal_file_uri = File::load($fid)->getFileUri();
// /sites/default/files/images/blah.jpg
$image_path = file_url_transform_relative(file_create_url($drupal_file_uri));
@hugronaphor
Copy link

This is deprecated since Drupal 9
https://www.drupal.org/node/2940031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment