6 July 2023

This code snippet demonstrates how to convert a file URI to a relative path in Drupal 7 using the drupal_realpath() function. By providing the file URI as input, the function returns the corresponding relative path, which can be useful for various file manipulation tasks.

Source code viewer
  1. $file_uri = 'public://path/to/file.txt';
  2.  
  3. // Convert file URI to a relative path.
  4. $relative_path = drupal_realpath($file_uri);
Programming Language: PHP