drupal_realpath有时不返回正确的路径

问题描述 投票:1回答:1

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

$imagePath = drupal_realpath('public://test_path');
print_r($imagePath);

它给出了以下输出

/用户//网站/ Drupal的/网站/默认/文件/ test_path

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

$imagePath = drupal_realpath('public://test_path/test');
print_r($imagePath);

它给出了输出

布尔(假)

为什么会出现这种行为?是否有可能在第二种方法中获得实际路径?

php drupal drupal-7
1个回答
0
投票

您可以使用file_stream_wrapper_get_instance_by_uri而不是drupal_realpath()

$dir_uri = file_stream_wrapper_get_instance_by_uri('public://test_path/test');
$dir_uri->realpath();
© www.soinside.com 2019 - 2024. All rights reserved.