Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I need to get the path for public:// at runtime. Is there a fx call to resolve it?

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

You can use the following code, to obtain the real path of public://.

if ($wrapper = file_stream_wrapper_get_instance_by_uri('public://')) {
  $realpath = $wrapper->realpath();
share|improve this answer
add comment

You can use the file_create_url function.

$uri = 'public://';
$path= file_create_url($uri)
share|improve this answer
add comment

See the following examples:

$scheme = file_uri_scheme($file);

if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
  $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
  $path = $wrapper->getLocalPath($file);


$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
$path = $wrapper->getDirectoryPath() . "/" . file_uri_target($uri);
print $path;

API for DrupalPublicStreamWrapper:



Why drupal_realpath('public://') returns sites/all/modules/current_module/sites/default/files path?

How do I get the public url of a file from the uri or filename

How can I convert a file uri to relative path?

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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