1

I use drupal_realpath() to do includes for some code samples I have:

 require_once(drupal_realpath('public://php_includes/functions.php'));

This gives the real path C:\www\sites\mysite\files\php_includes\functions.php.
What is the command to get the HTTP path http://mysite.com/sites/files/php_includes/functions.php?

The api documentation says "RealPath is deprecated"... if it's deprecated, what is supposed to replace it to get the same path (either C:\... or http://...)?

6

To get the HTTP path of a file, you need to use file_create_url($uri).

file_create_url('public://php_includes/functions.php');

This will output http://mysite.com/sites/files/php_includes/functions.php.

Regarding the fact that drupal_realpath() is deprecated, I think it's to warn developers to avoid relying on file system path and instead use wrappers.

  • Does it works well with S3FS module? – Moses Liao GZ Apr 6 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.