I badly need to create an .XML file inside my theme every time user comes to my site.
But I can’t.
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? 🙁
File system access is tricky thing between different possible server configurations. If you need to implement it reliably in WP you should look into its API for such.
See Using the WP_Filesystem.
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).