Is fopen() forbidden in WP?

I badly need to create an .XML file inside my theme every time user comes to my site.

But I can’t.

Read More

This code in header:

    <?php $ourFileName = "testFile.txt";
          $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
          fclose($ourFileHandle); ?>

Just does nothing. It doesn’t display “can’t open file”, but it doesn’t create the file as well.

I’m testing it at my /localhost machine and this code works perfectly everywhere there (so file permissions are alright), but not in WordPress.

Why is it happening? 🙁

Related posts

Leave a Reply

2 comments

  1. It’s not a WordPress problem; WordPress will execute fopen() just like any other PHP function.

    It may be an issue with your server configuration (e.g. safe mode).