【发布时间】:2019-02-12 11:30:15
【问题描述】:
当我在 Drupal 7 中尝试以下代码时,
$imagePath = drupal_realpath('public://test_path');
print_r($imagePath);
它给出以下输出
/Users//Sites/Drupal/sites/default/files/test_path
但是当我执行下面的代码时
$imagePath = drupal_realpath('public://test_path/test');
print_r($imagePath);
它给出了输出
布尔(假)
为什么会出现这种行为?第二种方法是否可以得到实际路径?
【问题讨论】:
-
如果文件夹不存在,则 drupal_realpath 返回 false ,确保您的文件夹 test 存在或在使用前使用 file_prepare_directory。或者您可以使用解决方法:
$imagePath = drupal_realpath('public://').'/test_path/test';