ohho ohho - 3 months ago 6x
PHP Question

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

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