当我在Drupal 7中尝试以下代码时,
$imagePath = drupal_realpath('public://test_path');
print_r($imagePath);
它给出了以下输出
/用户//网站/ Drupal的/网站/默认/文件/ test_path
但是当我执行下面的代码时
$imagePath = drupal_realpath('public://test_path/test');
print_r($imagePath);
它给出了输出
布尔(假)
为什么会出现这种行为?是否有可能在第二种方法中获得实际路径?
您可以使用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();