Php drupal_realpath有时不返回正确的路径

Php drupal_realpath有时不返回正确的路径,php,drupal,drupal-7,Php,Drupal,Drupal 7,当我在Drupal 7中尝试以下代码时 $imagePath = drupal_realpath('public://test_path'); print_r($imagePath); 它给出以下输出 /用户//站点/Drupal/Sites/default/files/test\u路径 但是当我执行下面的代码时 $imagePath = drupal_realpath('public://test_path/test'); print_r($imagePath); 它正在给出输出 布尔(假

当我在Drupal 7中尝试以下代码时

$imagePath = drupal_realpath('public://test_path');
print_r($imagePath);
它给出以下输出

/用户//站点/Drupal/Sites/default/files/test\u路径

但是当我执行下面的代码时

$imagePath = drupal_realpath('public://test_path/test');
print_r($imagePath);
它正在给出输出

布尔(假)


为什么它会表现出这种行为?可以在第二种方法中获取实际路径吗?

您可以使用
文件\u流\u包装器\u通过\u uri获取\u实例\u而不是
drupal\u realpath()


您可以使用
file\u stream\u wrapper\u get\u instance\u by\u uri
而不是
drupal\u realpath()


如果文件夹不存在,drupal\u realpath返回false,请确保文件夹测试存在,或者在使用它之前使用file\u prepare\u目录。或者您可以使用变通方法:
$imagePath=drupal\u realpath('public://')。/test\u path/test'<但不建议使用如果文件夹不存在,drupal\u realpath返回false,请确保文件夹测试存在,或者在使用它之前使用file\u prepare\u目录。或者您可以使用变通方法:
$imagePath=drupal\u realpath('public://')。/test\u path/test'<但不推荐
$dir_uri = file_stream_wrapper_get_instance_by_uri('public://test_path/test');
$dir_uri->realpath();