WordPress using file_get_contents in functions.php?

I’m trying to open a .p12 key file I placed in the same directory as functions.php. I tried using file_get_contents() to open the file, I also tried opening other random files and found that I could not.

PHP Warning: fopen(key.p12) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in path/wp-content/themes/theme-name/functions.php on line 26

I’ve been trying to get around this for hours.

Related posts

Leave a Reply

1 comment

  1. Doesn’t matter that functions.php and key.p12 are in the same directory. It all matters what the running script’s working directory is. e.g.

    /maindir/subdir/functions.php

    file_get_contents('key.p12');
    

    /maindir/script.php

    include('subdir/functions.php');
    

    In this case, the working directory will be maindir, and f_g_c() will be doing the equivalent of file_get_contents('/maindir/key.p12'), and fail, because the file is NOT in maindir.

    Check getcwd() at the point you’re doing the file_get_contents() call, and check what the working directory really is at that point. You’ll probably find it’s something completely different than the dir that functions.php lives in.