开发者

fopen works in normal PHP but not inside Drupal

Some PHP code worked well. However, when I port the code into a Drupal module, the $fp = fopen( 'language/unicode-big5.开发者_如何学Ctab', '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?


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).


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

drupal_get_path('module', $module_name);


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜