我有一些PHP脚本,将html文件写入文件夹。这完全在WordPress以外工作。但是,当我尝试将我的代码合并到插件中时,它不会再写入文件夹。我甚至尝试将它写入我在WordPress之外的根目录下测试它的原始文件夹,并且它也不会写入该文件夹。Wordpress不使用fwrite()写入文件夹;
这是写入html文件的函数。
function buildFrameFile($html, $filename){
$filename= '/wp-content/plugins/my-plugin/html/' . $filename . ".html";
$fh = fopen($filename, 'a');//open file and create if does not exist
fwrite($fh, $html);//write data
fclose($fh);//close file
return $filename;
}
我甚至试过
$fh = fopen($filename, 'a');
$fh = fopen($filename, 'a+');
$fh = fopen($filename, 'w');
$fh = fopen($filename, 'a+');
没有这些工作要么。
我在考虑在WordPress中,它可能是一些php.ini文件或.htaccess文件,需要在我想写入的文件夹中,但我卡住了。
*更新**
我发现在错误日志中的一些错误和如下:
错误:FWRITE()预计参数1是资源,布尔在给定....
$fh = fopen($filename, 'a');//open file and create if does not exist
fwrite($fh, $html);//write data
fclose($fh);//close file
第二更新
添加以下代码现在它在文件写入到文件夹
function buildFrameFile($html, $filename){
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$filename= $DOCUMENT_ROOT. '/wp-content/plugins/my-plugin/html/' . $filename . ".html";
$fh = fopen($filename, 'a');//open file and create if does not exist
fwrite($fh, $html);//write data
fclose($fh);//close file
return $filename;
}
但是现在当它调用打开文件时,它试图对从以下链接
/var/chroot/home/content/##/########/html/wp-content/plugins/my-plugin/html/c413c4976260c1a786e7a48be03f3ad2.html
打开它,我不相信链接将允许找到文件,因为它不会显示在浏览器中。
是你的测试发生在同一个服务器上的WordPress的安装?你的服务器错误日志说什么? – JMC 2013-05-03 15:58:56
是的,它在同一台服务器上,问题是我运行它时没有收到任何错误。 – 2013-05-03 16:02:13
Wordpress可能会抑制错误。你检查了日志吗? – JMC 2013-05-03 16:03:20