I learning how to write a WordPress plugin. I need some help writing some data to an XML file. I'm on my local machine, a Mac running MAMP. I have PHP 5.2.13. In my plugin, I've got:
$file_handle = fopen('markers.xml', 'w');
$stringdata = "Test Info";
fwrite($file_handle, $stringdata);
fclose($file_handle);
Running the above gives me the following error:
Warning: fopen(markers.xml) [function.fopen]: failed to open stream:
Permission denied in
/Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php
on line 73
Warning: fwrite(): supplied argument is not a valid stream resource in
/Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php
on line 75
Warning: fclose(): supplied argument is not a valid stream resource in
/Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php
on line 76
I tried using the absolute path in the $file_handle line: http://my_site/wp-content/plugins/my_plugin_folder/markers.xml. But, that didn't work.
I also tried changing the permissions on markers.xml as follows:
(Me): Read & Write
(unknown): Read only
everyone: Read & Write
For some reason, my Mac wouldn't let me change (unknown) to Read & Write. I'm not sure if that makes a difference. I right-clicked on the file and selected 'Get Info' in order to change the permissions.
In phpInfo(), I've got:
"Registered PHP Streams https, ftps, compress.zlib, compress.bzip2, php, file, data, http, ftp"
Is a WordPress setting causing the problem? or is it just PHP issue?
Any suggestions on how to solve this problem?
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…