【问题标题】:How to fix this warning: file_get_contents(): Unable to find the wrapper "public"?如何解决此警告:file_get_contents(): Unable to find the wrapper "public"?
【发布时间】:2011-05-22 21:00:12
【问题描述】:

我需要从下载的文件中读取一些元信息。但我不知道该怎么做。

这是我的代码:

// Path form field_file
$file = 'public://directory/filename.txt';
file_get_contents($file);

此代码导致此警告:

警告:file_get_contents():无法找到“公共”包装器 - 您在配置 PHP 时是否忘记启用它?

你知道我做错了什么吗?

【问题讨论】:

  • 什么是“公共”包装?从来没有听说过。这是 Drupal 特有的吗?你需要从下载的什么文件中读取什么样的元信息?
  • drupal.org/node/555118 是的,它是 drupal 特定的包装器。我需要从 TTF 文件中获取字体的名称和类型。

标签: php drupal filestream drupal-7


【解决方案1】:

共有三个内部流包装器privatepublictemporary,它们在this文件中定义。

你可能想要file_get_mimetype(),file_get_contents 是一个 PHP 函数,不会知道 drupal 文件 api。

file_get_contents(drupal_realpath($file));

会做阅读的诀窍。

如需上传,请查看file_save_upload()

【讨论】:

  • 谢谢。但它的工作原理很奇怪。如果“目录”不存在,drupal_realpath 将返回 FALSE。
【解决方案2】:

我相信这些包装器在 hook_boot() 或其他一些早期阶段不可用。 因此,请将您的代码移到另一个地方并检查是否可以解决问题。

【讨论】:

    【解决方案3】:

    我正在使用的修复是以下代码:

    echo base_path().variable_get('file_public_path',conf_path().'/files');
    

    它仍然没有解释为什么流不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 2022-12-26
      • 1970-01-01
      • 2017-07-10
      相关资源
      最近更新 更多