【问题标题】:drupal_realpath not returning the correct path sometimesdrupal_realpath 有时不返回正确的路径
【发布时间】: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';

标签: php drupal drupal-7


【解决方案1】:

您可以使用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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 2021-01-05
    相关资源
    最近更新 更多