5

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

这是我的代码:

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

此代码导致此警告:

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

知道我做错了什么吗?

4

3 回答 3

4

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

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

file_get_contents(drupal_realpath($file));

会做阅读的把戏。

如需上传,请查看file_save_upload()

于 2010-12-09T14:48:05.613 回答
2

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

于 2013-09-29T12:45:07.527 回答
0

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

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

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

于 2011-06-09T13:49:44.197 回答