fopen 在普通 PHP 中工作,但在 Drupal 中不起作用

发布于 2024-11-25 06:53:44 字数 544 浏览 0 评论 0原文

一些 PHP 代码运行良好。但是,当我将代码移植到 Drupal 模块中时, $fp = fopen( 'language/unicode-big5.tab', 'r' ); 无法按预期工作,并发出警告:

warning: fopen(language/unicode-big5.tab) [function.fopen]: failed to open stream: No such file or directory in /Users/me/Documents/Html/drupal/sites/all/modules/test_module/language.inc.php on line 197.

我尝试将所需的文件和文件夹放入 sites/default/files 中:

$fp = fopen( file_directory_path().'/language/unicode-big5.tab', 'r' );

返回相同的警告。

我该如何修复它?

Some PHP code worked well. However, when I port the code into a Drupal module, the $fp = fopen( 'language/unicode-big5.tab', 'r' ); does not work as expect, giving a warning:

warning: fopen(language/unicode-big5.tab) [function.fopen]: failed to open stream: No such file or directory in /Users/me/Documents/Html/drupal/sites/all/modules/test_module/language.inc.php on line 197.

I tried to put the required files and folder in sites/default/files:

$fp = fopen( file_directory_path().'/language/unicode-big5.tab', 'r' );

returns the same warning.

How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

-残月青衣踏尘吟 2024-12-02 06:53:44

那会工作得很好。

然而,该消息只是表明您的路径是错误的,您是否尝试过简单地查看它试图打开的路径?

只需执行以下操作,并相应地更正路径即可。

echo realpath(file_directory_path() . '/language/unicode-big5.tab');

如果路径正确,那么您需要检查权限,该用户是否有权访问该文件?尝试 chmod 777 并查看是否可以解决问题,如果可以,请删除 chmod 777 并相应修复它(用户/组权限)。

That will work perfectly fine.

However the message is simply stating that your path is wrong, have you tried a simply looking at what path it's trying to open?

Just do the following, and correct the path accordingly.

echo realpath(file_directory_path() . '/language/unicode-big5.tab');

If the path is correct, then you need to check permissions, does that user have access to the file at all? Try a chmod 777 and see if that helps the issue, if it does, remove the chmod 777 and fix it accordingly (user/group permissions).

天煞孤星 2024-12-02 06:53:44

最好使用遵循 drupal 标准的模块路径并将其添加到文件的路径中:

drupal_get_path('module', $module_name);

Its better to use module path following drupal standards and add that to the path of the file :

drupal_get_path('module', $module_name);

你如我软肋 2024-12-02 06:53:44

您的 Drupal 是否在与您所引用的文件不同的所有者下运行?文件可读吗? (chmod +r 文件)

Is your Drupal running under a different owner than the file you are referring to? Is the file readable? (chmod +r file)

孤云独去闲 2024-12-02 06:53:44

在 Drupal 7 和 8 中,有 drupal_realpath()

文档中不鼓励使用此函数。

https://api.drupal.org/api /drupal/includes!file.inc/function/drupal_realpath/7.x

In Drupal 7 and 8, there is drupal_realpath().

Use of this function is discouraged in the documentation.

https://api.drupal.org/api/drupal/includes!file.inc/function/drupal_realpath/7.x

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文